我正在使用来自另一个网站的 xml 字符串drupal_http_request
我目前正在尝试弄清楚如何将其作为 xml 抓取,它似乎不起作用,但是当我在浏览器中运行完全相同的 url 时,它会以 xml 格式返回信息关于如何执行此操作的任何想法 如果我在执行CC_时放入类似$headers = array("Content-Type: text/xml")
的东西,我想3 它会给我 XML 格式的数据,但这不是任何想法,提前感谢 以下是我的代码
<form method="post">
<p>Last Name: <input type="text" name="lastname" /><br />
First Name: <input type="text" name="firstname" /></p>
<p><input type="submit" value="Send it!"></p>
</form>
<?php
if($_POST)
{
$url = "https://pdb-services-beta.nipr.com/pdb-xml-reports/hitlist_xml.cgi?customer_number=testlogin&pin_number=testpin&report_type=1";
$url = $url . "&name_last=" . $_POST['lastname'] ."&name_first=". $_POST['firstname'];
$result = grabData($url);
$xml=simplexml_load_file("$result.xml");
$nipr_id = $xml->NPN;
echo "Agent " . $_POST['firstname'] . " " . $_POST['lastname'] . " Id is:". $nipr_id . "<br />'n";
}
?>
<?php
function grabData($url)
{
$http_contents = drupal_http_request($url);
if (!isset($http_contents->data)) {
throw new RuntimeException("Cannot get contents from the URL");
}
if($replace_special_characters)
$http_contents_data = str_replace('&','&', $http_contents->data);
else
$http_contents_data = $http_contents->data;
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $http_contents_data, $result);
xml_parser_free($xml_parser);
echo "Display http_contents_data " . $http_contents_data . "<br />'n";
echo "Display result " . $result . "<br />'n";
return $result;
}
?>
这是我收到的
LISTsamplelastname, samplefirstname samplemiddlenamesampleidsampleidstateDOB
当我通过浏览器运行 url 时,我得到这个
<?xml version='1.0' encoding='UTF-8'?>
<HITLIST>
<TRANSACTION_TYPE>
<TYPE>
LIST
</TYPE>
</TRANSACTION_TYPE>
<INDIVIDUAL>
<NAME>
samplelastname, samplefirstname samplemiddlename
</NAME>
<ID_ENTITY>
sampleid
</ID_ENTITY>
<NPN>
sampleid
</NPN>
<STATE_RESIDENT>
state
</STATE_RESIDENT>
<DATE_BIRTH>
dob
</DATE_BIRTH>
</INDIVIDUAL>
<INDIVIDUAL>
</INDIVIDUAL>
在Supdley和我的同事John Salevetti的帮助下,我找到了解决方案。只需将 xml 内容包装在 htmlspecialchars 中,XML 现在显示
答案是将有问题的 xml 内容包装在 htmlspecialchars 命令中,这将覆盖页面上非 html 字符的抑制。想向 Spudley 大喊大叫,他看了这段代码并提醒我非 html 字符抑制 谢谢 Spudley 帮助我不要在那个兔子洞里走得太远!
这是原来的台词....
echo "Display http_contents_data " . $http_contents_data . "<br />'n";
这是修改后的行...
echo "Display http_contents_data " . htmlspecialchars($http_contents_data) . "<br />'n";