[php] ALT 0160 niet gezien door trim

Pagina: 1
Acties:
  • 189 views sinds 30-01-2008
  • Reageer

Onderwerpen


Acties:
  • 0 Henk 'm!

  • TangLeFuzZ
  • Registratie: Juni 2001
  • Laatst online: 28-05-2024
Hey,

ik weet nu al vrij lang dat trim() de alt code 0160 niet als leeg teken/spatie ziet, wat dus best problemen op kan leveren omdat je trim functie dan eigenlijk zinloos is als iemand echt zou willen kloten.

Op php.net kwam ik dit tegen:
If you want to totally stop windows (dunno about other os's) peeps from adding spaces (say, you need to check there name against a special one to stop impersonations) use this:

$nick = ereg_replace("[\r\n\t\v\ ]", "", trim($nick));

It has the alt code 0160 added to it
Maar die werkt ook niet... hoe doen jullie het, of houden jullie geen rekening met ALT 0160?

Acties:
  • 0 Henk 'm!

  • pjonk
  • Registratie: November 2000
  • Laatst online: 08:27
Je kan altijd nog het volgende doen:
PHP:
1
$string = str_replace(chr(160), '', $string);


Toevoeging:
Vanaf PHP 4.1.0 kan je ook optioneel een charlist meegeven aan de trim functie.
Bijvoorbeeld:
PHP:
1
2
3
$clean = trim($binary,"\0x00..\0x1F");
// trim the ASCII control characters at the beginning and end of $binary
// (from 0 to 31 inclusive)

[ Voor 60% gewijzigd door pjonk op 10-02-2003 12:04 . Reden: Toevoeging ]

It’s nice to be important but it’s more important to be nice


Acties:
  • 0 Henk 'm!

  • TangLeFuzZ
  • Registratie: Juni 2001
  • Laatst online: 28-05-2024
JonkieXL schreef op 10 februari 2003 @ 11:52:
Je kan altijd nog het volgende doen:
PHP:
1
$string = str_replace(chr(160), '', $string);


Toevoeging:
Vanaf PHP 4.1.0 kan je ook optioneel een charlist meegeven aan de trim functie.
Bijvoorbeeld:
PHP:
1
2
3
$clean = trim($binary,"\0x00..\0x1F");
// trim the ASCII control characters at the beginning and end of $binary
// (from 0 to 31 inclusive)
Thanks, die str_replace werkt goed.
De 2e staat gewoon in de PHP manual ja, klopt, maar ik krijg er een foutmelding mee;

Warning: Invalid '..'-range passed to trim(), '..'-range needs to be incrementing in test.php on line 3

Acties:
  • 0 Henk 'm!

  • MSalters
  • Registratie: Juni 2001
  • Laatst online: 13-09 00:05
Voor alle duidelijkheid, alt-160 bedoel je waarschijnlijk de nonbreaking space mee( Unicode 00A0h) . Dat is dus geen ASCII karakter. Er is ook geen ASCII karakter 160, ASCII gaat maar tot de 127. Daarboven is gereserveerd voor nationale karakters, bvb Latin1-Latin15 (ISO8859) of Japans (Shift-JIS). chr(160) is dus moeilijk, dwz soms wel en soms niet een (nonbreaking) spatie.

Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein