Hi, I wonder if you can help me.I am doing a php tutorial. I am supposed to be able to open this file:

<?xml version="1.0"?>
<pet>
<name>Polly Parrot</name>
<age>3</age>
<species>Parrot</species>
<parents>
<mother>Pia Parrot</mother>
<father>Peter Parrot</father>
</parents>
</pet>

and this is the php file:

<?php
//set name of xml file

$file = "pet.xml";

//load file
$xml = simplexml_load_file($file) or die ("unable to load xml file");

//access xml data
 echo "Name: " $xml->name . "\n";
 echo "Age: " $xml->age . "\n";
 echo "Species: " $xml->species . "\n";
 echo "Parents: " $xml->parents->mother . " and " . $xml->parents->father . "\n";
 ?>

I have version 5.4 so simple xml should be enables, but I cannot open the file.Thanks

You are missing the dot after echo "Name:", the same happens for each line. So starting from the top, the first should be:

echo "Name: " . $xml->name . "\n";

Also, by enabling the error reporting at the top of the file:

error_reporting(E_ALL);
ini_set("display_errors", 1);

You should be able to see the error that explains the problem:

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in pet.php on line 8

Docs:

Bye!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.