Jonah Hart Jonah Hart - 1 year ago 84
PHP Question

Can't Parse link from XML

public function load ( )

$xml = simplexml_load_file('');

foreach ( $xml -> entry as $entry )

$link = $entry -> link;

echo'<div class="row">
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<div class="caption">
<h3>' . $entry -> title . '</h3>
<p>' . $entry -> content . '</p>
<p>' . $entry -> link . '</p>




When I try to show "$entry -> link" to match the tag in the xml feed it doesn't show anything.

I don't know what the issue is, I've researched but to no avail.

I've tried assigning $entry -> link to a variable outside of the forreach but that wont crack it.

Answer Source

The <link>-tag itself is empty. What you try to access is an attribute.

<link href="" />

You can get the attributes using the attributes()-function:

foreach ($xml->entry as $entry ) {
    echo '<p>'.$entry->link->attributes()->href.'</p>';

More information:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download