Find the img tags in a text

2

I have a random text:

$s = " eu sou campeao <img src='leo.jpg' /> teste lala  ";

I need to add the path of the image and look like this:

$s = " eu sou campeao <img src='img/leo.jpg' /> teste lala  ";

Note: I need to add "img /" inside the src directory. There may come several images, but I'll add the same string.

    
asked by anonymous 06.04.2017 / 22:06

1 answer

1

Just use str_replace to change src=' to src='img/' .

str_replace('src=\'', 'src=\'img/', $s);

Test this.

    
06.04.2017 / 22:32