Find img tags in text

Asked

Viewed 49 times

2

I have a random text:

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

and I need you to add the image path and stay that way:

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

Note: I need to add "img/" inside the src that has the directory. It can come several images, but I will add the same string.

1 answer

1


Just use str_replace, to exchange the src=' for src='img/'.

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

Test this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.