Popple3 Posted December 23, 2007 Share Posted December 23, 2007 I'm parsing XML, but many of the tags in the XML file (which I have no control over) have colons ( : ) in them, and as a result i get an "Unexpected ':'" parse error. Is there a way of escaping these colons, or removing them from the XML before it is parsed? I'm using PHP4... Thanks in advance Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/ Share on other sites More sharing options...
phpSensei Posted December 23, 2007 Share Posted December 23, 2007 maybe use str_replace(":","\:",$page); I don't know really. Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/#findComment-421859 Share on other sites More sharing options...
Popple3 Posted December 23, 2007 Author Share Posted December 23, 2007 Sadly, "\:" doesn't escape colons... Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/#findComment-421863 Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 Can you show us an example of your problem. Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/#findComment-421867 Share on other sites More sharing options...
phpSensei Posted December 23, 2007 Share Posted December 23, 2007 It should have worked, I don't see why a colon would be a problem here. If you want to remove them, just do str_replace(":", "" , $page); Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/#findComment-421869 Share on other sites More sharing options...
Popple3 Posted December 23, 2007 Author Share Posted December 23, 2007 Yeah, I meant to actually include it <?php include('xmlparser.php'); //Get the XML document loaded into a variable $xml = file_get_contents('http://picasaweb.google.com/data/feed/api/user/popple3?kind=album'); //Set up the parser object $parser = new XMLParser($xml); //Work the magic... $parser->Parse(); //Echo the plot of each <movie> foreach($parser->document->entry as $entry) { $imgurl = $entry->media:group->media:thumbnail->tagAttrs['url']; echo $entry->title[0]->tagData; echo "<img src=\"" . $imgurl . "\">"; } ?> And then that just returns: Parse error: parse error, unexpected ':' in /home/www/popple3.com/picasa.php on line 14 Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/#findComment-421870 Share on other sites More sharing options...
papaface Posted December 23, 2007 Share Posted December 23, 2007 Shouldnt it be :: ? I'm new to objects so I'm not sure. Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/#findComment-421872 Share on other sites More sharing options...
Popple3 Posted December 23, 2007 Author Share Posted December 23, 2007 Shouldnt it be :: ? I'm new to objects so I'm not sure. When I do that I get Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /home/www/popple3.com/picasa.php on line 13 Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/#findComment-421874 Share on other sites More sharing options...
darkfreaks Posted December 23, 2007 Share Posted December 23, 2007 <?php $pattern= ':;,.@/|\~`&-=+_'; $replace=''; $string='123456789'; preg_replace($pattern,$replace,$string); ?> Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/#findComment-422035 Share on other sites More sharing options...
PFMaBiSmAd Posted December 24, 2007 Share Posted December 24, 2007 I recommend echoing out the parsed data to see what it contains. Use var_dump() or print_r(). Also, provide a link to the xml class you are using so that someone could duplicate the problem and look into it. I suspect that media:group becomes media->group or 'media:group'. But echoing out the data would provide the definitive answer. Link to comment https://forums.phpfreaks.com/topic/82945-escaping-colons/#findComment-422053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.