i would love to do 5, can't. i only have 4 available on this server, can't be upgraded until the control panel is, yada, yada, yada....
seems to be the line breaks, if i remove all the line breaks, the issue goes away. not sure how to check for line breaks. i'm doing a reg ex thing for spaces, but not sure of syntax to remove line breaks. here's the whole code:
PHP Code:
if(!($fp=fopen("assets/employeee.xml","rt"))){
die('<p>Couldn\'t open XML.</p>');
}
$usercount=0;
$userdata=array();
$current='';
if(!($xml_parser=xml_parser_create())){
die('<p>Couldn\'t create parser.</p>');
}
xml_set_element_handler($xml_parser,"start_tag","end_tag");
xml_set_character_data_handler($xml_parser,"tag_contents");
while($data=fread($fp,4096)){
$data=eregi_replace(">"."[[:space:]]+"."< ",">< ",$data);
//echo '<h3>' . $data . '</h3>';
if(!xml_parse($xml_parser,$data,feof($fp))){
$reason = xml_error_string(xml_get_error_code($xml_parser));
$reason .= xml_get_current_line_number($xml_parser);
die($reason);
}
}
xml_parser_free($xml_parser);
echo '<h2>Starting name output: ' . $usercount . ' total</h2>';
for($i=0;$i<$usercount;$i++){
echo "<p><b>Name:</b> " . $userdata[$i]["title"] . " " . $userdata[$i]["first"] . " " . $userdata[$i]["last"] . '</p>';
}
// functions
function start_tag($parser,$name,$attrib){
//echo '<p>Start tag: ' . $name . '</p>';
global $usercount;
global $userdata;
global $current;
$current = $name;
switch($name){
case $name=="EMPLOYEE":{
$userdata[$usercount]["title"] = $attrib["TITLE"];
//echo '<p>Name: ' . $attrib["TITLE"];
}
}
}
function end_tag($parser,$name){
global $usercount;
global $userdata;
if($name=="EMPLOYEE"){$usercount++;}
}
function tag_contents($parser,$data){
global $usercount;
global $userdata;
global $current;
if(!$current){return;}
if($current=="FIRST"){
echo "<br>filling first: " . $data . "<br>";
$userdata[$usercount]["first"]=$data;
}
if($current=="LAST"){
$userdata[$usercount]["last"]=$data;
echo "filling last: " . $data . "<br>";
}
// if i trim out the data, works fine
/*if($current=="FIRST" && trim($data)!=""){
//echo "<br>filling first: " . $data . "<br>";
$userdata[$usercount]["first"]=$data;
}
if($current=="LAST" && trim($data)!=""){
$userdata[$usercount]["last"]=$data;
//echo "filling last: " . $data . "<br>";
}*/
}
Bookmarks