gaza165 Posted August 14, 2008 Share Posted August 14, 2008 $pattern = "/http:\/\/[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+/i"; $match = preg_match_all($pattern, $body, $matches,1); $gaz = $body; $i = 0; foreach($matches[0] as $url){ $replacement = "%TOKEN".$i."%"; $gaz = preg_replace("@$url@", $replacement, $gaz, 1); $i++; } $phrase = getSentences($gaz); foreach($matches as $value) { print_r($value); } I need a foreach loop to loop through the matches that are found and replace the %TOKEN0%, %TOKEN1% etc with the image urls. Someone must understand this code!! HELP!! Quote Link to comment https://forums.phpfreaks.com/topic/119624-for-each-loop-array/ Share on other sites More sharing options...
ignace Posted August 14, 2008 Share Posted August 14, 2008 it is not allowed to double post (http://www.phpfreaks.com/forums/index.php/topic,211788.msg964746.html#msg964746) bump instead Quote Link to comment https://forums.phpfreaks.com/topic/119624-for-each-loop-array/#findComment-616310 Share on other sites More sharing options...
gaza165 Posted August 14, 2008 Author Share Posted August 14, 2008 I have updated my ForEach loop and this is where i am at. $phrase = getSentences($gaz); foreach($matches as $value) { $string = getSentences($gaz); $i=0; $new = str_replace("%TOKEN".$i."%", $value[$i], $string); $i++; } echo $new; this seems to only replace the first token, i increment the $i variable by 1 so surely when the loop repeats it will replace the TOKEN1?? Quote Link to comment https://forums.phpfreaks.com/topic/119624-for-each-loop-array/#findComment-616323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.