php - preg_replace src img from text -
i'm looking way change src of img text.
example :
$var = "some text text text <img src=\"test1.jpg\"/> text text text text <img src=\"test2.jpg\"/>";
i change 2 src value in array :
$array = array("apple.jpg", "banana.jpg");
then $var should :
"some text text text <img src=\"apple.jpg\"/> text text text text <img src=\"banana.jpg\"/>"
i doing loop of every preg_match src of img don't know how can modify src in final var.
(sorry english :( )
thank.
edit :
thank answer
how can if then, modify src begin "data : src="data etc
another way it:
$var = "some text text text <img src=\"test1.jpg\"/> text text text text <img src=\"test2.jpg\"/>"; $array = array("apple.jpg", "banana.jpg"); $var = preg_replace_callback('#<img.+?src="([^"]*)".*?/?>#i', function($m) use (&$array) { return str_replace($m[1], array_shift($array), $m[0]); }, $var);
Comments
Post a Comment