0

I want to search the words in a php string and replace any word in the string that is in an array for example:

$array = array('john', 'peter', 'andrew', 'james', 'mark'); 
$string = "This is a photo from peter which he sent to mark";

Now I want to search all the words in the $string and replace any word that is within the $array with an image so the $string will now look like this:

$string = "This is a photo from <img src='peter.jpg'> which he sent to <img src='mark.jpg'>";

Please do anyone know an easy way to how I can achieve this?

I don't think it's a duplicate. In that question only a letter or word is replaced but in this case I need to replace any word in the string that is within an array

KANAYO AUGUSTIN UG
  • 2,078
  • 3
  • 17
  • 31

0 Answers0