XML and ampersands
I have a short script that gets an XML file from isbndb.com and parses it for three simple tags, then passes the information back to a script in the URL.
My problem occurs when there's an ampersand within the data of the XML file. I only get the text that comes after the ampersand. I've tried urlencode, htmlspecialchars, and htmlentities when the data is saved to the variables, but I'm obviously going in the wrong direction. Anybody have any tips?
EDIT: It's not pretty since it changes the data, but it works for all of my practical purposes.
The XML data loaded into a string and parsed a little at a time using this generic code:
while ($data = fread($xml_temp, 4096)){
// error handler
if (!xml_parse($xml_parser, $data, feof($xml_temp))){
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml _parser)), xml_get_current_line_number($xml_parser) ));
}
}
Right before the first if, I added:
$data = str_replace('&','and',$data);
I wasn't aware until I did some digging the parser actually sees the ampersand as &, but for some reason by the time the data is processed it doesn't put it all together correctly. By just eliminating the thing, my problems go away as well.
My problem occurs when there's an ampersand within the data of the XML file. I only get the text that comes after the ampersand. I've tried urlencode, htmlspecialchars, and htmlentities when the data is saved to the variables, but I'm obviously going in the wrong direction. Anybody have any tips?
EDIT: It's not pretty since it changes the data, but it works for all of my practical purposes.
The XML data loaded into a string and parsed a little at a time using this generic code:
while ($data = fread($xml_temp, 4096)){
// error handler
if (!xml_parse($xml_parser, $data, feof($xml_temp))){
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml
}
}
Right before the first if, I added:
$data = str_replace('&','and',$data);
I wasn't aware until I did some digging the parser actually sees the ampersand as &, but for some reason by the time the data is processed it doesn't put it all together correctly. By just eliminating the thing, my problems go away as well.
