error_reporting(E_ALL & ~E_NOTICE);
if (@is_file('functions.inc.php'))
require_once('functions.inc.php');
$xml = preg_replace('/(>)[\n\r\\s\t]+(<)/', '$1$2',
@file_get_contents('php://stdin'));
$parser = @xml_parser_create();
@xml_parse_into_struct($parser, $xml, $xmlArray, $tags);
@xml_parser_free($parser);
for ($i = 1; $i < @sizeof($xmlArray) - 1; $i++) {
foreach ($xmlArray[$i]['attributes'] as $attr =$val) {
foreach (array(&$attr, &$val) as $field) {
$field = str_replace('{', '{', str_replace('}',
'}', $field));
$tclList .= (preg_match('/[\s\t]+/', $field)) ? '{' .
$field . '} ' : "$field ";
}
}
}
echo trim($tclList);
?>
This converts XML that is inputted from stdin (a TCL script will input
the XML-read contents into the PHP script) into a TCL list.
However, the PHP script in question dies if stdin is too long. I don't
exactly know the "maximum length" it could be, if there is one, but I
do know that this scirpt will work with this:
php -q /home/ppowell/web/blah.php<?xml version="1.0" encoding="utf-8" ?><usa><state id="1" abbrev="AL"
name="Alabama"></state></usa>
But will fail with this:
php -q /home/ppowell/web/blah.php<?xml version="1.0" encoding="utf-8" ?><usa><state id="1" abbrev="AL"
name="Alabama"></state><state id="2" abbrev="AK"
name="Alaska"></state><state id="3" abbrev="AZ"
name="Arizona"></state><state id="4" abbrev="AR"
name="Arkansas"></state><state id="5" abbrev="CA"
name="California"></state><state id="6" abbrev="CO"
name="Colorado"></state><state id="7" abbrev="CT"
name="Connecticut"></state><state id="8" abbrev="DE"
name="Delaware"></state><state id="9" abbrev="DC" name="District of
Columbia"></state></usa>
[nothing is returned, and verifying: $xml = ">"]
Is there an actual size limit or is there something else wrong? Feel
free to play with this script as much as you like.
Thanx
Phil