I have the following html code stored in a php variable:
<p>This is a sample paragraph</p>
<img src="img/1.jpg">
<h1>This is my header</h1>
<img src="img/2.jpg">
<p>I hope someone can help me</p>
<img src="img/3.jpg">
And I have a php array which has three elements, exactly as many as the image elements in the html string:
Array(3){
[0]<img src="img/new1.jpg">
[1]<img src="img/new2.jpg">
[2]<img src="img/new3.jpg">
}
I'm trying to write a function which will replace the first img tag in the html string with the first array element, the second one with the second in the array and the third with the third in the array. So that at the end I get this:
<p>This is a sample paragraph</p>
<img src="img/new1.jpg">
<h1>This is my header</h1>
<img src="img/new2.jpg">
<p>I hope someone can help me</p>
<img src="img/new3.jpg">
Believe me I've no idea how to do this. If I would have an idea I would try but the problem is that I can't come to any logic for solving this problem. Any help would be really great.