Re: Regular expression newbie question, convert this: [::word1 \" word2 \" word3::] to : ".word1 " word2 " word3."

From: Date: Sat, 15 Jun 2002 10:54:24 +0000
Subject: Re: Regular expression newbie question, convert this: [::word1 \" word2 \" word3::] to : ".word1 " word2 " word3."
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-102332@lists.php.net to get a copy of this message
hi, thanks for the code. i tried. it only worked if the string is simply the one i wanna convert. but that particular string is in the middle of a long text, and there are multiple occurance, it won't. however, i did manage to come up with this code that worked. but i believe it can be improved on. it will identify all occurance of the specified pattern and do the necessary replacement throughout the whole string. preg_match_all("|\[::(.*)::\]|U", $longTxt, $matchedResult); for ($idx = 0; $idx < count($matchedResult[1]); $idx++) { $extract = stripslashes($matchedResult[1][$idx]); $longTxt = str_replace("[::{$matchedResult[1][$idx]}::]", "\".$extract.\"", $longTxt); } lance Analysis & Solutions wrote:
Lance: On Fri, Jun 14, 2002 at 11:41:34PM +0800, Lance wrote:
[::word1 \" word2 \" word3::] to: ".word1 " word2 " word3."
While I don't know if this is really what you need, it does do exactly what you want to do in your example: $Replace['\\'] = ''; $Replace['::'] = '.'; $Replace['['] = ''; $Replace[']'] = ''; $UserInput = '[::word1 \" word2 \" word3::]'; echo strtr($UserInput, $Replace); --Dan


« previous php.general (#102332) next »