PHP 문자열에서 앰퍼샌드 값을 구문 분석하려고합니다. 내 코드를 실행 한 후에도 빈 값을 반환하고 내 변수 ($ area)의 '앰퍼샌드'값 때문이라고 확신합니다. 나는 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는 나는
try urlencode ($ area) – andreimarinescu
무엇이 빈 값을 반환합니까? '$ area'의 값으로 인해 문제가 발생하는 이유는 무엇입니까? 엔티티를'$ seek' 변수에 넣기 전에 인코딩하지 않는 이유는 (CDATA 블록 내부에 있지 않는 한 엔코딩되지 않은'&'는 일반적으로 XML에서는 유효하지 않습니다)? –
@andreimarinescu : 작동하지 않습니다 – akinboj