Jump to content

Recommended Posts

$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!!

Link to comment
https://forums.phpfreaks.com/topic/119624-for-each-loop-array/
Share on other sites

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??

Link to comment
https://forums.phpfreaks.com/topic/119624-for-each-loop-array/#findComment-616323
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.