有两页。
http://miveo.dk/searchform.php http://miveo.dk/search.php?go
我正在尝试将搜索表单中的输入值解析为在php和curl中完成的http请求。
检查所说的行:看这里。
我确实回显了$ name值并正确解析了值。但它不会被解析为我尝试的HTTP请求。
任何想法我做错了什么? search.php中:
<html>
<body>
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/[A-Z | a-z]+/", $_POST['name'])){
$name = $_POST['name']; <-- LOOK HERE
$url = 'http://dev.api.ean.com/ean-services/rs/hotel/v3/list?minorRev=28';
$url .= '&apiKey=nwdzm6ph8j8qss4yg8w7pyfy';
$url .= '&cid=55505';
$url .= '&destinationString=$name'; <---- LOOK HERE
$url .= '&searchRadius=50';
$url .= '&supplierCacheTolerance=MED_ENHANCED';
$url .='&arrivalDate=09/04/2015&departureDate=09/05/2015&room1=2';
$header[] = "Accept: application/json";
$header[] = "Accept-Encoding: gzip";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt($ch,CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$response = json_decode(curl_exec($ch));
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>
<table>
<Tr>
<TD>
<?PHP
echo $name;
//for ($x=0; $x <=9; $x++)
//{
//print_r($url);
print_r("<BR>");
print_r("<pre>");
print_r ($response);
print_r("</pre>");
//}
?>
</TD>
</Tr>
</table>
</body>
</html>
答案 0 :(得分:0)
您需要:
$url .= "&destinationString=$name"; <---- LOOK HERE
或
$url .= '&destinationString=' . $name; <---- LOOK HERE
PHP仅在双引号字符串中进行变量替换,而不是单引号字符串。