28, May 2012

strange parse error - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: strange parse error
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: strange parse error  (Read 2377 times)
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« on: Oct 02, 2006, 09:07:46 am »

Hello,

I created a country select thats created with some custom XML parser:
http://www.bergtoys.com/ dealer.php?lang=nl-NL

the XML file is here:
http://www.bergtoys.com/ Connections/countries_xml.php?lang=nl

the strange is that the country "Nieuw Zeeland" has error in the html only for the dutch language, if you check the same select menu in the english langauge it works fine: http://www.bergtoys.com/ dealer.php?lang=en

this is the code I use to parse the XML feed:

<?php
class Country_select {

	
var 
$xml_file "http://www.bergtoys.net/Connections/countries_xml.php";
	
var 
$curr_val;
	
var 
$selected_val;
	
var 
$xml_parser;
	
var 
$featured;
	

	
function 
Country_select($current ""$lang "en"$elem_name "country"$disabled false$auto_submit false$form_name "") {
	
	
$this->selected_val $current;
	
	
$this->featured false;
	
	
$this->select_name $elem_name;
	
	
$this->disable $disabled;
	
	
$this->submit $auto_submit;
	
	
$this->form $form_name;
	
	
$this->xml_file .= "?lang=".$lang;
	
	
$this->select_parser();
	
}
	
function 
startElement($parser$name$attribs) {
	
	
$this->curr_val $name;
	
	
if (
$name == "country_list") {
	
	
	
echo 
"<select name=\"".$this->select_name."\"";
	
	
	
if (
$this->submit) echo " onchange=\"document.".$this->form.".submit();\"";
	
	
	
echo (
$this->disable) ? " disabled=\"disabled\">\n" ">\n";
	
	
}
	
	
if (
$name == "country_code") {
	
	
	
 echo (
$this->featured) ? "  <option style=\"font-weight:bold;\" value=\"" "  <option value=\"";
	
	
}
	
	
if (
count($attribs) > 0) {
	
	
	
if (
$attribs['feat'] == "y"$this->featured true;
	
	
}
	
}
	

	
function 
endElement($parser$name) {
	
	
if (
$name == "country_list") echo "</select>\n";
	
	
if (
$name == "country"$this->featured false;
	
	
if (
$name == "country_name") echo "</option>\n";
	
}
	
function 
characterData($parser$data) {
	
	
if (
$this->curr_val == "country_code") {
	
	
	
echo (
$data == $this->selected_val) ? $data."\" selected=\"selected\">" $data."\">";
	
	
}
	
	
if (
$this->curr_val == "country_name") echo utf8_decode($data);
	
}
	
function 
select_parser() {
	
	
$this->xml_parser xml_parser_create();
	
	
xml_set_object($this->xml_parser$this);
	
	
xml_parser_set_option($this->xml_parserXML_OPTION_CASE_FOLDING0);
	
	
xml_set_element_handler($this->xml_parser"startElement""endElement");
	
	
xml_set_character_data_handler($this->xml_parser"characterData");
	
	
$fp fopen($this->xml_file"r") or die("Error reading XML data.");
	
	
while (
$data fread($fp4096)) {
	
	
	
$data eregi_replace(">[[:space:]]+<""><"$data);
	
	
	
xml_parse($this->xml_parser$datafeof($fp)) or die("Error while parsing XML data");
	
	
}
	
	
fclose($fp);
	
	
xml_parser_free($this->xml_parser);
	
}
}
?>
« Last Edit: Sep 03, 2009, 10:23:21 am by Olaf »

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Oct 02, 2006, 09:21:40 am »

That's really strange.

1) What happens if you enable case folding? xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, 1);

2) What version of php you have?

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Oct 02, 2006, 09:32:06 am »

Quote
1) What happens if you enable case folding? xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, 1);
that wil not work...

Quote
2) What version of php you have?
4.3.11

the funny thing is that I use the same XML data with a DOM parser in php5 and there is not that problem...

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #3 on: Oct 02, 2006, 09:39:39 am »

I know, the xml parser was bugy before php 5.

Try to use a parser class or even better/faster do a custom preg to parse that data.

Here is an example for RSS feeds :

Code:
<?php
$searchfile 
eregi("<item>(.*)</item>"$readfile ,$arrayreg);
$filechunks explode("<item>"$arrayreg[0]);
$count count($filechunks);
for(
$i=$i<=$count-;$i++)
{
   
ereg("<title>(.*)</title>",$filechunks[$i], $title);
   
ereg("<link>(.*)</link>",$filechunks[$i], $links);
   
ereg("<description>(.*)</description>",$filechunks[$i], $descr);

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Oct 02, 2006, 10:10:25 am »

Sad
that is my first xml parser in php4 and you gonna tell me that I have to throw it away?

lol

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #5 on: Oct 02, 2006, 10:15:01 am »

Sad
that is my first xml parser in php4 and you gonna tell me that I have to throw it away?

lol

It's ok, you can throw away your host, and get one with php5 Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: Oct 02, 2006, 10:18:58 am »

Sad
that is my first xml parser in php4 and you gonna tell me that I have to throw it away?

lol



It's ok, you can throw away your host, and get one with php5 Smiley
hehe, I have php4 and php5 on this server but I need a php5 extenstion to call the script
« Last Edit: Oct 02, 2006, 10:27:39 am by olaf »

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #7 on: Oct 02, 2006, 10:24:53 am »

You posted an empty post.....

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #8 on: Oct 02, 2006, 10:28:50 am »

You posted an empty post.....
No,  I wrote my message in the quote, that happens often because of the quick reply Wink

Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=4321
Tags : php html xml rss Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: strange parse error
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 01:56:07 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.