0

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

2
Contributors
1
Reply
10
Views
3 Years
Discussion Span
Last Post by cereal
0

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!

Edited by cereal

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.