22, November 2008

strange parse error - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ 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

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


It's time to use PHP5!


« on: Oct 02, 2006, 10: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 Visit through proxy

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

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 Visit through proxy

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 blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #1 on: Oct 02, 2006, 10: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 Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6440
39464 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Oct 02, 2006, 10: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...


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #3 on: Oct 02, 2006, 10: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 Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6440
39464 credits
Members referred : 374


It's time to use PHP5!


« Reply #4 on: Oct 02, 2006, 11: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


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #5 on: Oct 02, 2006, 11: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 Visit through proxy or twitter Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6440
39464 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: Oct 02, 2006, 11: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, 11:27:39 AM by olaf »


Last blog : Just a better Internet portal provided by Google
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8249
42481 credits
Members referred : 3



« Reply #7 on: Oct 02, 2006, 11:24:53 AM »

You posted an empty post.....

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

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6440
39464 credits
Members referred : 374


It's time to use PHP5!


« Reply #8 on: Oct 02, 2006, 11: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


Last blog : Just a better Internet portal provided by Google
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....

Topic sponsors:
Get a permanent link here for $1.99!


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?
Nov 22, 2008, 12:29:38 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!


Forum Statistics
Total Posts: 37.736
Total Topics: 7.650
Total Members: 4.396
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: thomas09

30 Guests, 4 Users online :

12 users online today:



Readers

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