Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract data from XML 1

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
I have a simple XML file:

Code:
<?xml version=&quot;1.0&quot; standalone=&quot;no&quot;?>
<config>
  <season>winter</season>
</config>

How can I get the season value into PHP? Thanks.
 
Like this:

Code:
<?php

$file = &quot;config.xml&quot;;

if (!($fp = fopen($file, &quot;r&quot;))) {
    die(&quot;could not open XML input&quot;);
}

while ($data = fread($fp, 4096)) {
    $xml .= $data;
}

$season = preg_match (&quot;/<season>(.*)?<\/season>/&quot;, $xml);

echo $season;

?>
Regards
David Byng
bd_logo.gif

davidbyng@hotmail.com
 
oops!!

I mean like this:

Code:
<?php

$file = &quot;config.xml&quot;;

if (!($fp = fopen($file, &quot;r&quot;))) {
    die(&quot;could not open XML input&quot;);
}

while ($data = fread($fp, 4096)) {
    $xml .= $data;
}

preg_match (&quot;/<season>(.*)?<\/season>/&quot;, $xml, $season);

echo $season[1];

?>
Regards
David Byng
bd_logo.gif

davidbyng@hotmail.com
 
PHP 4.2.2 and I set the xml file permissions to 777... still null.
 
Weird...

I have copied/pasted just what you posted. Still no go.

I love stuff like this. :(
 
Hold the phone.

I just deleted the files from my server... the reuploaded them.

It works fine. Weird.

Thanks man.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top