我正在向RESTful Web服务提交URL请求。当我在url中提交变量,例如“NGF和trkA”时,我能够从远程服务器检索XML响应。但是,当我输入“NGF / trkA”时,我的请求失败了。我真的不明白为什么我使用rawurlendcode()。请参阅以下代码:
<?php
/*After pdf parsing, the result is contained in $fullText.*/
$fullText="NGF/TrkA*";
/*Remove line breaks.*/
$fullText_clean = str_replace("\n", " ", $fullText);
/*Excise the first 2 sentences of $fullText_clean (or 100 characters).*/
$truncated = substr($fullText_clean,0);
// Properly encode $truncated.
$truncated_encode = rawurlencode($truncated);
// Plug this variable, $truncated_encode, into the search url.
$xml = 'http://www.ebi.ac.uk/europepmc/webservices/rest/search/query='.$truncated_encode.'&resulttype=core';
// Return SimpleXMLElement object
$xmlObject = simplexml_load_file($xml);
if($xmlObject){
//Return information within the desired tag(s).
$title = $xmlObject->resultList->result[0]->title;
echo $fullText."<br />".
$fullText_clean."<br />".
$truncated."<br />".
$truncated_encode."<br />".
$title;
/*echo $title."<br />".$truncated;*/
}else{
echo "Failed to retreive SimpleXMLElement object.";
}
?>
这是$ fullText =“NGF / trkA”时出现的错误:
Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://www.ebi.ac.uk/europepmc/webservices/rest/search/query=NGF%2FTrkA%2A&result type=core" in /Applications/XAMPP/xamppfiles/htdocs/Lifescieco_pdfUpload/puttingitTogether.php on line 21
Failed to retreive SimpleXMLElement object.