I get html content from ckeditor and i have following html content
<p><strong>Hello</strong></p>
<p><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABVYAAAMACAIAA" style="height:131px; width:234px" /></p>
<p><strong>How are you</strong></p>
<p><img alt="" src="data:image/png;base64,ABAXKuVAAAAA3NCSVQICAjb4U/gAAAgAElEQV" style="height:142px; width:253px" /></p>
<p><strong>Good Morning</strong></p>
<p> </p>
Now i want to replace src
of each image tag with different image name. Let says for example
<p><strong>Hello</strong></p>
<p><img alt="" src="img.jpg" style="height:131px; width:234px" /></p>
<p><strong>How are you</strong></p>
<p><img alt="" src="test.jpg" style="height:142px; width:253px" /></p>
<p><strong>Good Morning</strong></p>
<p> </p>
source of image is dynamically bind. so it can be anything.after this replacement i save this html content to database.
i have done with
$image_name ='<p><strong>Hello</strong></p>
<p><img alt="" src="img.jpg" style="height:131px; width:234px" /></p>
<p><strong>How are you</strong></p>
<p><img alt="" src="test.jpg" style="height:142px; width:253px" /></p>
<p><strong>Good Morning</strong></p>
<p> </p>';
$html = preg_replace('!(?<=src\=\").+(?=\"(\s|\/\>))!', 'img.jpg',$image_name );
But this replace all src same.
I want whole content same except src
of <img>
tag. I need to replace this content using regex. I prefer regex because i want to save this replaced html into database. If any other solution works then that is also good.