Search code examples
phphtmlxmlzillow

Reading Zillow XML File with PHP


I have an XML file I want to read, but can't seem to make sense of it.

To access the file I pulled you can type in:

http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=X1-ZWz1gyo1562s5n_6sext&address=155+Demar+Blvd&citystatezip=Canonsburg%2C+PA

I'm doing this through PHP, so my code looks like:

<html>

<head>
<title>Hellow World</title>
</head>
<body>


<?php
$zillow_id = 'X1-ZWz1gyo1562s5n_6sext';

$search = '155 Demar Blvd';
$citystate = 'Canonsburg PA';
$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->lotSizeSqFt . "<br>";

?>

</body>
</html>

I had expected this code to result in the printout of the lot size - in square feet - to the screen. No dice.

However, the line of code:

echo $data->response->results->result->zpid . "<br>";

returns the expected value for the zpid parameter: 49785503.

In an ideal world the line of code:

echo $data->response->results->result->lotSizeSqFt . "<br>";

would return: 9000.

What am I doing wrong?


Solution

  • You're using the wrong endpoint in your code.

    Your endpoint: http://www.zillow.com/webservice/GetSearchResults.htm

    The correct endpoint: http://www.zillow.com/webservice/GetDeepSearchResults.htm

    Using the GetDeepSearchResults will return the results you're looking for.