Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] ...no subject... From: Dan Delaney (Dionysos <email protected>)
Date: 03/25/99

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
____________________________________________________________________________
 Daniel G. Delaney * Dionysos <email protected> * www.Dionysia.org/~dionysos
 PGP Public Key: http://Dionysia.org/~dionysos/pgp5.html

     "Only two things are infinite: the universe and stupidity--
      and I'm not sure about the former."
                                          --Albert Einstein

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