Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I parse a PHP object when the attribute name is *? [duplicate]

Tags:

json

object

php

Possible Duplicate:
Special characters in property name of object

I'm parsing a JSON response from MediaWiki's API: Requested URL

I run it through json_decode() and then pull some pieces of it. The problem I have is that the attribute name for the content is *. I get a PHP error when I try to access the content ( the 140,950 character string at the end of my vardumped json_decoded example below ) like this:

foreach( $Response->query->pages as $page_id => $Page ) {
    $this->id                   = $Page->pageid;
    $this->title                = $Page->title;
    $this->content_with_markup  = $Page->revisions[0]->*;
}

The PHP Error: PHP Parse error: syntax error, unexpected '*'

The pageid and title work fine.

Here is the piece of JSON_Decoded object that is giving me problems:

object(stdClass)#5 (1) {
  ["11968"]=>
  object(stdClass)#6 (4) {
    ["pageid"]=>
    int(11968)
    ["ns"]=>
    int(0)
    ["title"]=>
    string(17) "George Washington"
    ["revisions"]=>
    array(1) {
      [0]=>
      object(stdClass)#7 (2) {
        ["contentformat"]=>
        string(11) "text/x-wiki"
        ["*"]=>
        string(140950) "{{About|the first President of the United States|other uses}}...

How do I access the content contained in the attribute named *?

like image 459
T. Brian Jones Avatar asked Mar 31 '26 18:03

T. Brian Jones


1 Answers

Same as always.

...->{'*'}->...
like image 87
Ignacio Vazquez-Abrams Avatar answered Apr 02 '26 12:04

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!