Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] ...no subject... From: CIMPOESU Teodor (teo <email protected>)
Date: 03/25/99

Dan Delaney wrote:

> On Thu, 25 Mar 1999, CIMPOESU Teodor wrote:
> > > $stripped = ereg_replace("@$#^&*()", "'", $input);
> > most of those chars are special for a regex.You must escape them:
> > ereg_replace("[@ | \$ | # | \^| \& | \* | \( | \)]+","",$input)
>
> Aside from escaping many of the characters, the main thing wrong
> with your regex there is that you don't have them in [ ]. It's
> looking for that exact sequence of characters. But CIMPOESU's
> example isn't exactly correct either--you also can't use spaces,
> because it will look for those spaces. If you don't put the
> characters inside [ ] you have to use the | to mean "OR", but
> characters inside [ ] are automatically ORed by the vary nature of
> the use of [ ] in regular expressions. So, for example, the
> following are equivalent:
>
> $newstring ereg_replace("a|A", "-", $oldstring);
> $newstring ereg_replace("[aA]", "-", $oldstring);
>
> So, what you need to do is put [ ] around your characters, and
> escape several of them with a \ (@, # and & should be allright).
> Thus:
>
> $stripped = ereg_replace("[@\$#\^&\*\(\)]", "'", $input);
>
> I just tried that and it worked fine.
>
> -- Dan

ok, I've already tried "[@$#^&*()]" - as Adam suggested - and works fine
without any escaping.

CIMPOESU Teodor, Web Programmer

@ DIGICOM S.A. Bucharest, Romania
@ Internet, site development
@ teo <email protected>,+(401)-330.47.28

official home page: http://www.digiro.net/

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3
List administrator:  zeev-list-admin <email protected>