Forum Moderators: coopster
Got a problem with a php script.
I've got a variable $page holding a text. After that I do a str_replace to replace some recurring words with a single WORD (this will make my query easier). After that I do a preg_match looking for the specific WORD and some words after this WORD. The WORD occurs multiple times in the text though and I only get the first WORD. How can I get all the other WRDS?
Here is a piece of the script :
$page = $contents;
$pageis .= htmlspecialchars($page) . "<br>\n";
$pagefiltered = str_replace("bla bla bla","WORD",$pageis);
preg_match('/WORD(.+?)\/(.+?)\//im',$pagefiltered,$result);
echo "$result[1],$result[2]";
Greetz,
Turbo
You might find your answer in
preg_match_all() [be2.php.net].
Happy coding!
$page = $contents; $pageis .= htmlspecialchars($page) . "<br>\n"; $pagefiltered = str_replace("bla bla bla","WORD",$pageis); preg_match_all('/WORD/',$pagefiltered,$result); echo sizeof($result[0])." <br />\n"; for($i=0;$i<sizeof($result[0]);$i++) { echo $result[0][$i]; if ($i!=sizeof($result[0])-1) { echo ","; } } (I simplified the regexp because I didn't get any matches with it during testing.)