Thread: Trim function
View Single Post

  #3 (permalink)  
Old 12-09-2005
Willem-Jan
 
Posts: n/a
Default Re: Trim function

Hilarion wrote:
>> Whem I try to trim a variable from a posted field, it results in the
>> variable that still has space in the first position.
>> This only with posted fields in IE, not in Netscape. Is this a known
>> problem, and what can I do about it?

>
>
>
> Maybe it's not a normal space character, but for example a non-breaking
> space or there's some other non-printable character which is not
> trimmed and prevents trimming of the space character.
>
> Try this code:
>
> $text = $_REQUEST['problematic_text'];
> $len = strlen( $text );
> echo 'The text length is: ' . $len . "<br />\n";
> echo 'The codes of characters are: ';
> for( $i = 0; $i < $len; $i++ )
> {
> printf( '%d/0x%02X ', ord( $text{$i} ), ord( $text{$i} ) );
> }
> echo "<br />\n";
>
> This should output the codes of characters (decimal code and hexadecimal
> code - separated with slash) separated with spaces.
>
>
> Hilarion


It seemed to be a non-breaking space. Now I remove it with

trim($string, "\xA0")

Thanx!
Reply With Quote