PHP + XML

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
micha80
Forum Newbie
Posts: 2
Joined: Mon Aug 25, 2003 10:12 am
Location: Berlin

PHP + XML

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
micha80
Forum Newbie
Posts: 2
Joined: Mon Aug 25, 2003 10:12 am
Location: Berlin

Post by micha80 »

thx volka,

i will try this. if this works there is no more pressure on me. ;)
User avatar
coos
Forum Newbie
Posts: 8
Joined: Mon Aug 18, 2003 9:45 am
Location: Scarborough, UK
Contact:

Woooooah!

Post 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
[xNet]DrDre
Forum Newbie
Posts: 8
Joined: Wed Oct 01, 2003 7:06 am

Post 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
Post Reply