我想解析PHP字符串中的&符号值。在我运行我的代码后,它保持返回空白值,我确信这是因为我的变量($区域)中的“&”值。我试过htmlspecialchars,html_entity_decode但无济于事。请看下面的代码:无法解析PHP字符串中的&符号
<?php
/** Create HTTP POST */
$accomm = 'ACCOMM';
$state = '';
$city = 'Ballan';
$area = 'Daylesford & Macedon Ranges';
$page = '10';
$seek = '<parameters>
<row><param>SUBURB_OR_CITY</param><value>'. $city .'</value></row>
<row><param>AREA</param><value>'. $area .'</value></row>
</parameters>';
$postdata = http_build_query(
array(
'DistributorKey' => '******',
'CommandName' => 'QueryProducts',
'CommandParameters' => $seek)
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata)
);
/** Get string output of XML (In URL instance) */
$context = stream_context_create($opts);
$result = file_get_contents('http://national.atdw.com.au/soap/AustralianTourismWebService.asmx/CommandHandler?', false, $context);
?>
PLS我怎么解决这个 感谢
尝试urlencode($面积) – andreimarinescu
什么返回空白值?为什么你确定你的问题是因为'$ area'中的值而出现的?为什么在将实体放入'$ seek'变量之前不对它们进行编码(因为非编码的'&'通常在XML中无效,除非在CDATA块中)? –
@andreimarinescu:不起作用 – akinboj