Trim function

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-09-2005
Willem-Jan
 
Posts: n/a
Default Trim function

Hi all,

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?

Thanx,
WJ
Reply With Quote
  #2 (permalink)  
Old 12-09-2005
Hilarion
 
Posts: n/a
Default Re: Trim function

> 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
Reply With Quote
  #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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:40 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0