Page 1 of 1

PHP + XML

Posted: Mon Aug 25, 2003 10:12 am
by micha80
hi @all,

i am not a english one so if i have some errors in my words, please be cool. :wink:

i have to write a website for some artists and they have the great idea to fill in news and some short infos on their own. as i heard that i thought about an xml solution but there is a problem right now. i dont want to write down all the content in one xml-file so i created 2 for testing. all the php-parse code is written down in 2 classes which will produce 2 different menues. when i include the second class-file and create the second menue as an object, nothing happened. my first thouhg was that i can not parse 2 xml-file but i still dont want to believe this. so i tried to get back to one class with one xml-file and create 2 different object which do the same (create mainmenue). the first one works fine but the second one dont comes up. during the code i have put some "echo"-functions and i recognized that the startParse-function, from the second object, didnt start. i will give you a link with the content files and it'll be very cool if anyone can take a look at this. please, i need some help!

thx a lot, michael

link: http://www.farbwahl.de/php_xml.zip

Posted: Mon Aug 25, 2003 11:08 am
by volka
PHP Fatal error: Cannot redeclare startelement() (previously declared in php_xml\bin\mainmenue.php:21) in php_xml\bin\mainmenue.php on line 21
You cannot redeclare functions even if they are within another function/method.
Either use string create_function ( string args, string code) or make the callbacks methods of the class; you can use them for xml_set_element_handler by passing an array (<instance>, <method>)
e.g.

Code: Select all

xml_set_element_handler($this->parser, array($this, "startElement"), array($this, "endElement"));
as a sidenote: if there is no attribute NAME php will produce a warning for

Code: Select all

$element_attribute["NAME"] = strtoupper($element_attribute["NAME"]);
maybe you should test the existence first. Same with $m_activ = $_REQUEST["m_activ"]; in news.php

Posted: Mon Aug 25, 2003 3:28 pm
by micha80
thx volka,

i will try this. if this works there is no more pressure on me. ;)

Woooooah!

Posted: Wed Aug 27, 2003 6:10 am
by coos
Sorry to butt in- I've got nothing constructive to add to this post, but can I just say I'm well impressed!

I've been studying php for about 9months now, and my head is still hurting a bit, but I'm getting there- or I thought I was!

ha ha!

Keep up the hard work, guys!

Coos

Posted: Thu Oct 02, 2003 6:50 am
by [xNet]DrDre
Well heres the exact function your looking for!

Code: Select all

<?
// xNetwork GetBetween Function
function GetBetween($start,$end,$string){
$starts=strpos($string,$start);
$starts=$starts + (strlen($start));
$ends=strpos($string,$end);
$ends=$ends-$starts;
return substr($string,$starts,$ends);
}

// Example
/*
echo GetBetween("<id>","</id>","<id>DrDre</id>");
*/
?>
If your not to heavy into php, i suggest not reading it and just using it :P

I was looking for this script and then realized how easy it was to make lol