This is a discussion on Trim function within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi all, Whem I try to trim a variable from a posted field, it results in the variable that still ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
> 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 |
|
|||
|
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! |
![]() |
| Thread Tools | |
| Display Modes | |
|
|