PHP: calling a simplexml child tag

Trying to parse a YouTube feed using PHP

simplexml_load_file();

I can access other tags quite simply using

$xml->id;

When I try to access

<openSearch:totalResults>

with

$xml->openSearch->totalResults;

I get no results

+3
source share
2 answers

openSearch- this namespace is not a tag name, nor a parent, or anything like that. Somewhere in the document, there will be an attribute xmlns:openSearchthat defines the openSearch namespace (with a URL).

You can use the method childrento get the children of a specific namespace and do something like:

$xml->children('openSearch', true)->totalResults

( URL- 'openSearch' true , , - , )

+4

XML, , :

$xml->children('openSearch', true);

.

0

Source: https://habr.com/ru/post/1746966/


All Articles