How to get values from XML?


There is such a repeating XML structure:

 <link rel="license" type="text/html" href="">
 <link rel="enclosure" type="image/jpeg" href="">

I need to get the value of href only where rel="enclosure" (to link to an image).

Doing this in a loop:

$xml = simplexml_load_string($result);

 foreach ($xml->entry as $pixinfo) {

 echo $pixinfo->link[1]['href'];


But in this structure, then two, then one value link. And when you take via the array index, sometimes you get what you need.
That is, I need to just select only the link rel="enclosure"

Is there any concise decision or need to run additional checks for this in a loop?
The documentation I read didn't help.

Thanks in advance for the help!
July 9th 19 at 12:48
2 answers
July 9th 19 at 12:50
I'm not really php, but I think something like this:
July 9th 19 at 12:52
in a pinch you can use preg_match_all
this is a very extreme method! must be some "native" the idea - Bethel_Steuber87 commented on July 9th 19 at 12:55

Find more questions by tags PHPXML