DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Can't open any xml file (http://www.daniweb.com/forums/thread53108.html)

pillow Aug 23rd, 2006 1:52 am
Can't open any xml file
 
I have installed apache 2.2.3 and PHP 5.1.5 on Win XP (IIS is also set up on different port) I have try the sample code from php.net; however, it keeps giving me error on opening the file please help.

[php]<?php
$file = "data.xml";
$depth = array();

function startElement($parser, $name, $attrs)
{
global $depth;
for ($i = 0; $i [ $depth[$parser]; $i++) {
echo " ";
}
echo "$name\n";
$depth[$parser]++;
}

function endElement($parser, $name)
{
global $depth;
$depth[$parser]--;
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input"); //it keeps dying here~~
}

while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
?>[/php]

Thank you in advance,
Pillow

Puckdropper Aug 23rd, 2006 12:10 pm
Re: Can't open any xml file
 
Try moving your initial variables down to just before the block where they're defined. PHP doesn't support global variables as other languages do, so there's no reason to define something above function blocks.

(I'm not sure if this will solve it, but it might.)

pillow Aug 25th, 2006 4:21 am
Can't load any external files
 
I found out that the real problem is somehow i am not able to load any external files from php. My current setting is Apache 2.2.3 PHP5.15 on WinXP. Is there any setting I have to make to get it load an external file?
Thanks,


Quote:

Originally Posted by Puckdropper (Post 245683)
Try moving your initial variables down to just before the block where they're defined. PHP doesn't support global variables as other languages do, so there's no reason to define something above function blocks.

(I'm not sure if this will solve it, but it might.)



All times are GMT -4. The time now is 4:41 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC