Re: skip file_get_contents

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ahmed Abdel-Aliem wrote:
> hi, i have a script that parses data from xml document
> my problem is sometimes i get error when getting file content from xml
> file fails
> so how can u make the script ignore that part when it fails to pull
> the data from the xml file.
>
> here is the script :
>
> $xp = xml_parser_create();
> xml_set_character_data_handler($xp,'h_char');
> xml_set_element_handler($xp,'h_estart','h_eend');
> $listing = 0;
> $found_listings = array();
> $tag_name = '';

$text = file_get_contents("http://someXMLdocument.xml";);
if ($text){
  xml_parse($xp, $text);
}

//> xml_parse($xp,file_get_contents("http://someXMLdocument.xml";));
>
> function h_char($xp,$cdata) {
> 	global $listing, $tag_name;
> 	if (is_array($listing) and $tag_name) {
> 		$listing[$tag_name] .=
> str_replace(''',"'",str_replace('&','&',str_replace('\\$','$',$cdata)));
> 	}
> 	return true;
> }
>
> function h_estart($xp,$name,$attr) {
> 	global $listing, $tag_name;
> 	if ($name == 'SITE') {
> 	    $listing = array();
> 	}
> 	else {
> 		$tag_name = strtolower($name);
> 	}
> 	return true;
> }
>
> function h_eend($xp,$name) {
> 	global $listing, $tag_name, $found_listings;
> 	if ($name == 'SITE') {
> 		$found_listings[] = $listing;
> 		$listing = null;
> 	}
> 	$tag_name = '';
> 	return true;
> }
>
> echo "hi, i am xml data"
> xml_parser_free($xp);
>
> can anyone help me with that please?
> --
> Ahmed Abdel-Aliem
> Web Developer
> www.ApexScript.com
> 0101108551
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux