user2997267
user2997267

Reputation: 11

XML String into PHP

I feel like I'm going crazy. I need to take a string of text from an xml file, and define it as a PHP variable and output it into an HTML page. I can't figure out why this wont work. Any ideas??

I have this xml document (people.xml):

<?xml version="1.0"?>
<datas>
 <person>
  <people>
   <owner>Joe Blow</owner>
  </people>
 </person>
</datas>

This PHP (db.php):

<?php 


$xml = simplexml_load_file('people.xml')

or die("Error: Can't load people");

$xml->person->people->owner = $owner;


?>

This HTML(index.php):

<?php include 'db.php';?>

<label for="owner-1"><?php echo $owner ?></label>

Upvotes: 1

Views: 35

Answers (1)

karthikr
karthikr

Reputation: 99620

Assuming everything else is right / Based on the code you have shown,

$xml->person->people->owner = $owner;

should be

$owner = $xml->person->people->owner;

You are trying to assign the value of $owner to $xml->person->people->owner It should be the other way round.

Upvotes: 2

Related Questions