Jump to content

[SOLVED] PHP4 and XML


kirk112

Recommended Posts

I have a script which creates and xml file using the code below.

 

How can I pase this xml file using php. I am currently using xml_parse($xml_parser,file_get_contents($file)); but this get the php code and not the out putted xml.

 

I can't get my head around how to parse the outputted xml using php

 

<?php
header('Content-Type: text/xml');
header('Content-Disposition: inline; filename=sample.xml');
include_once('page_config.inc.php');
$vars = get_defined_vars();
print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
print "<root>\n";
foreach($vars['js_type'] as $key => $value) {
$v = 'js_type_'.$key;
print "<js_config>\n";
print "<array_key>$key</array_key>\n";
print "<header>{$vars[$v]}</header>\n";
print "</js_config>";
}
print "</root>\n";
?>

 

This give me the following xml

 

 <?xml version="1.0" encoding="iso-8859-1" ?> 
- <root>
- <js_config>
 <array_key>1</array_key> 
 <header>ALL JAVASCRIPT FILES</header> 
 </js_config>
- <js_config>
 <array_key>2</array_key> 
 <header>TABS JAVASCRIPT FILES</header> 
 </js_config>
- <js_config>
 <array_key>3</array_key> 
 <header>STANDARD JAVASCRIPT FILES</header> 
 </js_config>
 </root>

 

Thanks for your help!

Link to comment
https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/
Share on other sites

** Bump **

 

tried everything I can think of, there must be a simple way of doing this

 

if i use

 

$file  = file_get_contents("../includes/page_config_xml.inc.php");

print nl2br(htmlentities($file));

 

I get

 

<?php

header('Content-Type: text/xml');

header('Content-Disposition: inline; filename=sample.xml');

include_once('page_config.inc.php');

$vars = get_defined_vars();

print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";

print "<root>\n";

foreach($vars['js_type'] as $key => $value)

{

$v = 'js_type_'.$key;

print "<js_config>\n";

print "<array_key>$key</array_key>\n";

print "<header>{$vars[$v]}</header>\n";

print "</js_config>";

}

print "</root>\n";

?>

 

instead of the xml only AHHHHHHHHHHHHh

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367052
Share on other sites

no if I use echo I get

 

<?php
header('Content-Type: text/xml');
header('Content-Disposition: inline; filename=sample.xml');
include_once('page_config.inc.php');
$vars = get_defined_vars();
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
echo "<root>\n";
foreach($vars['js_type'] as $key => $value) 
{
$v = 'js_type_'.$key;
echo "<js_config>\n";
echo "<array_key>$key</array_key>\n";
echo "<header>{$vars[$v]}</header>\n";
echo "</js_config>";
}
echo "</root>\n";
?>

 

Thanks for your help - really can't get my head around this

Link to comment
https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367150
Share on other sites

Hi

 

I have one php file that creates and prints out an xml file.

 

What I am trying to do is open the php file (from a seperate script) and get the xml content so that I can manipulate it.

 

But when ever I use fopen, get_file_contents etc all I get is the php script and not the xml content

 

Hope this explains better.

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367162
Share on other sites

Ok so maybe in the file that creates the XML, instead of echo'ing or print'ing, use a variable, say $xml

 

so

 

<?php
$xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
$xml .= "cdcsdcs";
// etc..

 

and then in your other php file, after you have included this file, just use the variable $xml.

 

<?php
//...
include("xmlgenerator.php");
// your variable is now set
xml_parse($xml) // or whatever
echo $xml;

 

im i following you now? hope so :)

 

tdw

Link to comment
https://forums.phpfreaks.com/topic/72763-solved-php4-and-xml/#findComment-367169
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.