views:

17

answers:

2

Hi,

When I parse an rss file with SimpleXMLElement, I get this object :

object(SimpleXMLElement)#307 (1) {
  [0]=>
  string(39) "http://workspace/wordpress/hello-world/"
}

$var->0 doesn't works.

I don't know how to do it :(

thanks.

A: 

It behaves like an array

echo $var[0];

In this case - when there's only one (child) element - you don't even have to use the index

echo $var;
VolkerK
$var[0] gives the same result. $var is a SimpleXMLElement. Thanks
charles
yeah thanks it was the answer
charles
A: 

can someone explains why I have to do this to have the url :

$k = $var.'';
var_dump($k);
charles
The . operator is only defined for strings. I.e. first php implicitly casts/converts both operands (left and right of the dot) to string. The cast SimpleXMLElement->string results in a string with the text content of the xml element. This happens in any case where an (implicit or explicit) cast to string occurs. see http://docs.php.net/language.oop5.magic#language.oop5.magic.tostring
VolkerK
ok i did now (string)$var, it's better for my eyes:p
charles