Create a gist now

Instantly share code, notes, and snippets.

[ Posted by Imran Hamzah ] Change image src php code.
$question_data = '<p>My questions here....</p><p>&nbsp;</p><p><img class="img-responsive" src="/uploads/images/questions/93_20161017102613.jpg" style="max-height:400px;" /></p>';
$xml = new DOMDocument();
//Initial Dom
//Find only image and convert url
//Process to convert url
$imgNodes = $xml->getElementsByTagName('img');
$arr_image_file_names = [];
$new_src = '';
for ($i = $imgNodes->length - 1; $i >= 0; $i--) {
$imgNode = $imgNodes->item($i);
$image_file_names = pathinfo($imgNode->getAttribute('src'), PATHINFO_BASENAME);
// Replace with new src
$new_src = 'http://myurl/qst/def/img/v1/'.$image_file_names;
echo ($new_src);
//Update into new array
//Convert back to DOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment