问题
So I'm starting this thread to fix a (likely syntax) error I encountered while implementing the answer by steven.yang at this question.
I tried his suggestion here, but got the error:
Unterminated regular expression literal.
This looks like a minor thing to fix, but I myself am not sure how to fix it.
Thanks!
update
since using jsonp makes it access the xml file, would it be possible to tell the computer to ignore any errors, just return the content of the <webcite_url>
tags?
回答1:
This php script will copy an external xml file to your local server. This will then allow you to parse that file instead.
I'm just working on a project that involves working with external data- you'll just need to execute this script when you want to update the xml file.
<?php
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL, 'http://*path/to/external.xml*');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec ($ch);
curl_close ($ch);
if (@simplexml_load_string($xml)) {
/**
* Create a new file
*/
$fp = fopen('*desiredfilename*.xml', 'w');
fwrite($fp, $xml);
fclose($fp);
}
?>
回答2:
The URL you're requesting isn't JSONP.
You get a syntax error when the browser tries to parse the XML response as Javascript.
来源:https://stackoverflow.com/questions/9356109/unterminated-regular-expression-literal-error-while-parsing-xml-data-from-a-fo