PHP and XML Newbie

Associate
Joined
21 Sep 2007
Posts
453
I am looking to learn some basic PHP and XML functions, for making a control panel for a Flash banner.

Currently I am using SQL to store some variables, but I wish to change this to XML.

I have started looking at the tutorials on Kirupa.com but i can only Just get my head around the basic XML tutorial.

I can make a page that will display the XML data, but the next task is to figure out how to inject the data (a couple of numbers and maybe some text) into my previous PHP code e.g. <? echo $fade; ?> (fade being an integer)

My XML file would be:

Code:
<?xml version="1.0"?> 
    <variables>
        <fade>1</fade> 
        <holdLength>5</holdLength> 
</variables>

Beyond displaying them, I am lost. For what i need, they do not need displaying, but simply passed into the PHP code shown.

Links to good, easy to understand XML tutorials are very welcome!
 
Thanks for the replies folks, but I managed to figure it out after carefully going through one of the Kirupa tutorials.

And the solution was much cleaner then what you have posted :confused:

Hector - I have no problems with FlashVars, why do you hate them so? Also, you keep insisting they don't work in IE6, when they clearly do :confused:

Here is the PHP code i used in the end:

Code:
$file = "flash.xml";

$xml_fade_key = "*VARIABLES*FADE";
$xml_holdLength_key = "*VARIABLES*HOLDLENGTH";

function startTag($parser, $data){

	global $current_tag;
	$current_tag .= "*$data";
}

function endTag($parser, $data){

	global $current_tag;

	$tag_key = strrpos($current_tag, '*');

	$current_tag = substr($current_tag, 0, $tag_key);

}

function contents($parser, $data){

	global $current_tag, $xml_fade_key, $xml_holdLength_key, $fade, $holdLength;
	switch($current_tag){
		case $xml_fade_key:
			$fade = $data;
			break;
		case $xml_holdLength_key:
			$holdLength = $data;
			break;

	}

}

$xml_parser = xml_parser_create();

xml_set_element_handler($xml_parser, "startTag", "endTag");

xml_set_character_data_handler($xml_parser, "contents");

$fp = fopen($file, "r");

$data = fread($fp, 80000);

if(!(xml_parse($xml_parser, $data, feof($fp)))){
    die("Error on line " . xml_get_current_line_number($xml_parser));
}

xml_parser_free($xml_parser);

fclose($fp);

Simple huh?
 
Sic - I can look through the code i posted, and see how it works, looking at what you posted, I have no clue where it should so, or how it works. Hence I view my code as simpler. Remember I said I am totally new to this.

Thankyou for your input eitherway
 
Back
Top Bottom