Re: won't erase "$"
| From: | CC Zona | Date: | Tue, 23 Oct 2001 05:52:45 +0000 |
| Subject: | Re: won't erase "$" | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-71900@lists.php.net to get a copy of this message | ||
In article <3BD4FEEE.46F071CF@courrier.usherb.ca>,
jtjohnston@courrier.usherb.ca (Jtjohnston) wrote:
> Suggestions for improvement anyone?
> > > $mystring = ereg_replace (".html", "", $mystring);
> > > $mystring = ereg_replace (".htm", "", $mystring);
> > > $mystring = ereg_replace (" ", "", $mystring);
> > >
> > > $mystring = ereg_replace ("}", "", $mystring);
> > > $mystring = ereg_replace ("{", "", $mystring);
> > > $mystring = ereg_replace ("\|", "", $mystring);
> > > $mystring = ereg_replace ("\]", "", $mystring);
> > > $mystring = ereg_replace ("\[", "", $mystring);
> > > $mystring = ereg_replace ("\\\\", "", $mystring);
<snip much, more of same>
Since you ask...
You can save yourself a lot of trouble and a ton of wasted function calls
by checking out a POSIX (ereg_*) or PCRE (preg_*) syntax tutorial. When
you want to match space or punctuation characters, character classes are a
Good Thing(TM). That whole loooooong block of code could be rendered with
a single good, concise regex. With the bonus of a lot less escaping.
--
CC