为什么不回显变量?

时间:2018-06-23 12:16:23

标签: php html

试图回显$data ...在将数据发送到$citystate$address之后它什么也不打印?

<html>
<body>
<?php

  $zillow_id = 'X1-ZWz18i4rtwj56z_8xo7s'; //the zillow web service ID that you got from your email

  $search = $_GET['address'];
  $citystate = $_GET['citystate'];
  $address = urlencode($search);
  $citystatezip = urlencode($citystate);

  $url = "http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=$zillow_id&address=$address&citystatezip=$citystatezip";

  $result = file_get_contents($url);
  $data = simplexml_load_string($result);

  echo $data->response->results->result[0]->zpid;

?>

<form action="index.php" method="post">
Address: <input type="text" name="address"><br>
City, State, ZIP: <input type="text" name="citystate"><br>
<input type="submit">
</form>
</body>
</html>

如果有一个WP插件也可以做到这一点,那就太好了。但是我仍然很好奇。

1 个答案:

答案 0 :(得分:0)

如果数据错误,

API不会返回任何数据,因此您必须在URL中添加正确的参数。

检查此链接-尝试以下网址 http://example.com/?zws-id=X1-ZWz18i4rtwj56z_8xo7s&address=2114+Bigelow+Ave&citystate=Seattle%2C+WA返回数据并显示zpid

结果:48749425

在此处检查zillow API的完整数据-http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz18i4rtwj56z_8xo7s&address=2114+Bigelow+Ave&citystatezip=Seattle%2C+WA