I'm trying to split this image string: $output = "<img typeof="foaf:Image" src="http://asite.dev/sites/default/files/video/MBI_Part%201_v9.jpg" width="1920" height="1080" alt="" />
I'm doing it like this: $split = explode('"', $output);
But when I print_r($split);
it returns:
Array ( [0] => typeof="foaf:Image" [2] => src="http://makingitcount.dev/sites/default/files/video/MBI_Part%201_v9.jpg" [3] => width="1920" [4] => height="1080" [5] => alt="" [6] => /> )
No second value! Where'd it go? split[1]
throws an error, of course. I also notice that the "<img
" part of the string isn't in the array either.
The problem stems from the parsing of the html tag. If you remove the
<img
at the beginning of the html string, you'll notice the rest of the attributes will parse into an array with a proper number sequence (including a '1' element). You can solve your problem by formatting your quotes to tell php not to parse the html and treat the entire unit strictly as a string.If you want to bypass this whole mess, you can also just use regular expression matching to collect tag information and pass it into an array. $matches[0][*] will contain all of your tag attributes, and $matches[1] contains the tag itself (img)
which gives you