Re: New to php3 - pattern matching?

From: Date: Sat, 22 Jul 2000 16:06:19 +0000
Subject: Re: New to php3 - pattern matching?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-7692@lists.php.net to get a copy of this message
Thanks for the help - got it going with $pattern = "/\//"; $replacement = ""; $result = preg_replace($pattern, $replacement, $newterm); $term =$result; Seems long winded compared to Perl... Cheers Geoff > At 03:32 AM 7/21/00 -0400, Sterling Hughes wrote: > >> have just installed php3 and mysql etc ... have used perl before > >> > >> if I have $item which has a "/" in it and I want to remove it - perl > >> would be something like $item =~ s/\///; > > > >$item = preg_replace("/\//", "", $item); > > > >-Sterling > > Now I would have said: > > str_replace ("/", "", "$item"); > > Can anyone explain the benefit of using preg_replace over str_replace? The > examples I see on this list always look so dang obfuscated :) > > Later, > Jeff Gannaway > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#7692) next »