never_had_a_name
never_had_a_name

Reputation: 93156

how to get an objects property

ive got an object that looks like this with print_r():

SimpleDOM Object ( [0] => continent )

i wonder how i could get the continent as a string?

i have tried gettype($object[0]);

it still says its an object.

i just want to get the string "continent".

Upvotes: 0

Views: 68

Answers (3)

Peter Bailey
Peter Bailey

Reputation: 105878

Is this SimpleDOM the one you're using?

If so, it looks like that value would be stored in the _Element::$tagName variable. So maybe try this?

echo $object[0]->tagName;

Upvotes: 2

Nicolò Martini
Nicolò Martini

Reputation: 5220

Try with

get_class($object[0])

But i've not understood if you want the class name or other.

Upvotes: 0

prodigitalson
prodigitalson

Reputation: 60413

Im not familar with SimpleDOM but it would seem to me that its something similar in implementation to SimpleXMLElement. If this is the case then casting the object to a string should get you what you want:

$continent = (string) $object;

or from its parent node you can probably access it like so:

$continent = $parent->continent;

These are only guesses though. I would taka look at the SimpleDOM documentation.

Upvotes: 0

Related Questions