note 37231 deleted from ref.xml by didou
| From: | didou@php.net | Date: | Fri, 07 Nov 2003 08:39:18 +0000 |
| Subject: | note 37231 deleted from ref.xml by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-60058@lists.php.net to get a copy of this message | ||
Note Submitter: Dan
----
Am I missing something here? I have not been able to figure out what this "fread() breaking
thing" is all about. As far as I can tell, either expat or php caches any incomplete data until
a start or end tag is completed and no tags are broken or lost. The code below demonstrates this.
The only way to distort the data is if you do it yourself in the handler functions.
function _startElement(&$p, $name, $attr)
{
echo "<$name>";
}
function _endElement(&$p, $name)
{
echo "</$name>\n";
}
function _characterData(&$p, $data)
{
echo $data;
}
$fp = fopen('test.xml', 'r');
$p = xml_parser_create();
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($p, '_startElement', '_endElement');
xml_set_character_data_handler($p, '_characterData');
// Will work with anything over 1
while ($data = fread($fp, 2)) {
// Works with or without the 3rd parameter
if(!xml_parse($p, $data, feof($fp))) {
exit('What's the frequency, Kenneth?!');
}
}
xml_parser_free($p);
fclose($fp);
exit;
test.xml
<?xml version="1.0"?>
<root>
Here is some character data
</root>
Tested on WinXP-Apache 1.3.27-PHP 4.3.3