For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > September 2007 > Regular expression help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Regular expression help
Karin J

2007-09-26, 8:00 am

Hi everyone

I am using a ereg_replace to strip all but certain allowed characters
from a string:
$string =3D ereg_replace("([^ 0-9A-Za-z=C5=A0=C5=92=C5=BD=C5=A1=C5=93=C5=BE=
=C5=B8=C3=80-=C3=96=C3=98-=C3=B6=C3=B8-=C3=BE-])","",$string);

I would like to extend this to allow HTML character references of the
form "&#number;" where number is the three or four digit code number
of the character. Examples would be "ä" and "ẽ".

I am sorry but regular expressions hurt my brain!

Thankyou in advance
Karin

Steve

2007-09-26, 7:01 pm


"Karin J" <k.x.jensen@googlemail.com> wrote in message
news:1190800981.199664.221350@19g2000hsx.googlegroups.com...
Hi everyone

I am using a ereg_replace to strip all but certain allowed characters
from a string:
$string = ereg_replace("([^ 0-9A-Za-zSOZsozYÀ-ÖØ-öø-þ-])","",$string);

use preg. read the manual for an explanation.

I would like to extend this to allow HTML character references of the
form "&#number;" where number is the three or four digit code number
of the character. Examples would be "ä" and "ẽ".

I am sorry but regular expressions hurt my brain!

as well as reading the manual. ;^) were you to have, you'd notice that you
would have been instructed to use preg rather than ereg for a miriad of
reasons. not only that, but you'd see an example of preg_replace doing
*exactly* what you're asking help on.

if regex hurts your brain, don't use it...you won't be able to maintain it
once you initially write it. it is a language in itself.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com