PHP - echo not working

I am having a problem with some php. I can get my results to print but I can't echo a specific section of the xml. This is the code I am using:

I have removed the cdata headings. However, When I try to return [propertyname] it returns nothing.

  • Adam Czajczyk
    • Support Gorilla

    Hi Ellen

    I hope you're well today and thank you for your question!

    What you get in $xml variable is not a simple string or a regular PHP array but it's a PHP object, so it needs slightly different treatment. Take a look at this code:

    $xml=simplexml_load_file("", null, LIBXML_NOCDATA);
    $my_property = $xml->property->propertyname;
    echo 'PROPERTY NAME:' . $my_property .'<hr>';
    echo '<pre>';
    echo '</pre>';

    The "crucial" part is how the value of propertyname is fetched to the $my_property variable here:

    $my_property = $xml->property->propertyname;

    You could "echo" it directly but I decided to fetch it to variable to show it better and for each of use. This way you should be able to fetch other data as well, just see the structure of the $xml object.

    As you can see I also wrapped print_r() output with "pre" tags. It's a simple trick but you'll appreciate it when you load the code :wink: It formats arrays' and objects' data display in a way that you can easily see entire tree and spot relationships (parent-child, key-value etc).

    I hope that helps :slight_smile:

    Best regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.