With curl I dowload XML file and saved localy. How can I check this file is valid XML. After donloadedd I save to mysql information from this file.
$url = '<URL to XML>';
$local_path = "myxml.xml";
$file_handle = fopen($local_path, "w");
ob_start();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FILE, $file_handle);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // times out after 4s
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$result = curl_exec($ch);
curl_close($ch);
ob_end_clean();
fclose($file_handle);
I tried this but not working.
if (filesize('myxml.xml')>0) {
$str_xml = file_get_contents('myxml.xml');
if(simplexml_load_string($str_xml)){
echo 'XML';
}else{
echo 'NOT XML';
}
Code returned this WRONG
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found in
Where I wrong ?
Thanks in advance !