categories - PHP Parsing json decoded result from wikipedia api MediaWiki -


i trying use wikipedia mediawiki api page data. query url :

http://en.wikipedia.org/w/api.php?action=parse&format=json&page=nirnayam_%281991_film%29

one of properties returned categories:

"categories":[{"sortkey":"","*":"telugu-language_films"},{"sortkey":"","*":"1991_films"},{"sortkey":"","*":"indian_films"}] 

a var_dump after json_decode :

foreach($wiki_page_data_json->parse->categories $cat) {     var_dump($cat); } 

gives me :

object(stdclass)[21] public 'sortkey' => string '' (length=0)
public '*' => string 'telugu-language_films' (length=21)

object(stdclass)[22] public 'sortkey' => string '' (length=0)
public '*' => string '1991_films' (length=10)

object(stdclass)[23] public 'sortkey' => string '' (length=0)
public '*' => string 'indian_films' (length=12)

i can access public 'sortkey' $cat->sortkey

question - how access value in public '*' ?

you can access object properties names contain special characters using notation:

foreach($wiki_page_data_json->parse->categories $cat) {     var_dump( $cat->{'*'} ); } 

interesting reading > https://stackoverflow.com/a/10333200/67332


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -