Why Isnt This Working?

Discussion in 'PHP' started by cgo85, Aug 25, 2008.

  1. #1
    I've been spending hours trying to figure this out... why isn't this working to parse this: http://developer.trulia.com/docs/LocationInfo/getNeighborhoodsInCity


    <?php
     
    
    // Construct the GetPriceResearch REST call 
    $apicall = "http://api.trulia.com/webservices.php?library=LocationInfo&function=
    getNeighborhoodsInCity&city=Seattle&state=WA&apikey=MY_KEY";
    
    // Load the call and capture the XML document returned by API
    $xml = file_get_contents($apicall);
    
    
    // Check to see if the XML response was loaded, else print an error
    if ($xml) {
    	$results = '';
    
    	if( $xml->Errors )
    	{
    		// If there was an error in the response, print a warning.
    		$results = "Uh oh, there was an error making the query!";
    	}
    	else
    	{
    		// Gather our statistics
    		$LocationInfo = $xml->LocationInfo;
    
    		$city = $LocationInfo->city;
    		$state = $LocationInfo->state;
    		$neighborhood = $LocationInfo->neighborhood['name'];
    
    		$results .= "<b>city:</b> $city<br/>";
    		$results .= "<b>state:</b> $state<br/>";
    		$results .= "<b>neighborhood:</b> $neighborhood<br/>";
    
    	}
    }
    // If there was no XML response, print an error
    else {
    	$results = "Dang! Must not have got the XML response!";
    }
    
    ?>
    PHP:

     
    cgo85, Aug 25, 2008 IP
  2. rcadble

    rcadble Peon

    Messages:
    109
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    rcadble, Aug 26, 2008 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    file_get_contents() doesn't return an object. I guess you're looking for something like simplexml_load_file().
     
    nico_swd, Aug 26, 2008 IP
  4. cgo85

    cgo85 Peon

    Messages:
    380
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    rcadble, you've been alot of help to me... unfortunately I don't know how to do what you stated above.

    nico_swd, I tried simplexml_load_file($api_call); & it didnt work for me
     
    cgo85, Aug 26, 2008 IP