php3-list | 199903
Date: 03/25/99
- Next message: CIMPOESU Teodor: "Re: [PHP3] Strip chars from string"
- Previous message: Jeff Fox: "[PHP3] NT authorization from PHP under Linux?"
- In reply to: CIMPOESU Teodor: "Re: [PHP3] ...no subject..."
- Next in thread: CIMPOESU Teodor: "Re: [PHP3] ...no subject..."
- Reply: CIMPOESU Teodor: "Re: [PHP3] ...no subject..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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>
- Next message: CIMPOESU Teodor: "Re: [PHP3] Strip chars from string"
- Previous message: Jeff Fox: "[PHP3] NT authorization from PHP under Linux?"
- In reply to: CIMPOESU Teodor: "Re: [PHP3] ...no subject..."
- Next in thread: CIMPOESU Teodor: "Re: [PHP3] ...no subject..."
- Reply: CIMPOESU Teodor: "Re: [PHP3] ...no subject..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

