Parsing an img src with DOM returns only the first character of string

146 views Asked by At
$doc = new DOMDocument();
$document=$doc->loadHTML($introtext);
$imageparse = $doc->getElementsByTagName('img');
$i=0;

foreach ($imageparse as $parser) {

$images[$i]= $parser->getAttribute('src');
$i++;
}
var_dump($images[0]);

INTROTEXT VAR:

<p>ssdasadssdasadssd</p>
<p>ssdasad</p>
<p>ssdasad</p>
<p>ssdasad</p>
<p><img src="images/images.jpg" alt="" /></p>
<p>ssdasad</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

var_dump($images[]) returns always the first character of the string,instead of whole string. example: "images/images.jpg" = i . if i set src="gotrekt" , i get "g" as output. The funny thing is that yesterday in my home i used the same code to do it and it worked,i just copy pasted my files with usb today in work.

ALso i notice that var_dump($introtext) give this :

enter image description here

this isnt legit right ? SHouldnt it shows the html tags instead of getting executed? $introtext is the content of Joomla Articles so maybe its not a coding but a joomla issue at the end ? I removed all the security patterns for articles but still nothing changed.

0

There are 0 answers