Fw: [PHP] preg_replace - understanding

From: Date: Tue, 08 Jul 2003 22:40:12 +0000
Subject: Fw: [PHP] preg_replace - understanding
Groups: php.general 
Request: Send a blank email to php-general+get-154452@lists.php.net to get a copy of this message
----- Original Message ----- From: "Micah Montoy" <montmica@isu.edu> To: <php-general@lists.php.net> Sent: Tuesday, July 08, 2003 4:01 PM Subject: [PHP] preg_replace - understanding > I'm trying to understand how the code works within the preg_replace function > but the manual is just obscure as the examples are. Anyway, I am looking to > use it to replace "\\" in a string with "/" and I can not figure how how. > At first, I thought I could just do: > > $filevalue = preg_replace("'\\', /", $filevalue); > > but it doesn't do anything. If someone could relate what it is and what the > parts mean between the (), I would appreciate it. > > thanks You're not using the function correctly. You've got the search string and replace string tied up into one input there. They need to be separate. $filevalue = preg_replace('\\', '/', $filevalue); http://www.php.net/manual/en/function.preg-replace.php However you should consider using the str_replace() function in your case since you aren't doing any pattern matching and it's a lot faster than preg_replace(). $filevalue = str_replace('\\'. '/', $filevalue); http://www.php.net/manual/en/function.str-replace.php -- Kevin

« previous php.general (#154452) next »