arrays - PHP - Replace string src value with data uri -


good day.

i have array holds data uri of img.

$var = array( [0] => data:image/png;base64,ivborw0kggoaa... [1] => data:image/png;base64,rw0kkggoaswaa... ); 

and have string.

$foo = '<p>test 7/31/2</p> <p>&nbsp;<img src="/media/1.png" alt="" /></p> <p><img src="/media/2.png" alt="" /></p>'; 

how can replace src in $foo data uri array in $var?

result like.

$foo = '<p>test 7/31/2</p> <p>&nbsp;<img src="data:image/png;base64,ivborw0kggoaa..." alt="" /></p> <p><img src="data:image/png;base64,rw0kkggoaswaa..." alt="" /></p>'; 

any ideas do!

try this:

$images = [     "/media/1.png" => 'data:image/png;base64,ivborw0kggoaa...',     "/media/2.png" => 'data:image/png;base64,rw0kkggoaswaa...' ];  $url = '<p>test 7/31/2</p> <p>&nbsp;<img src="/media/1.png" alt="" /></p> <p><img src="/media/2.png" alt="" /></p>'; $url = str_replace(array_keys($images), array_values($images), $url); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -