note 37231 added to ref.xml
| From: | Dan at rn2 dot php dot net | Date: | Fri, 07 Nov 2003 07:43:54 +0000 |
| Subject: | note 37231 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60048@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37231
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37231&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37231&report=yes
Search -- http://master.php.net/manage/user-notes.php