0

basically what i'm looking at doing is take a user defined variable, in this case the name of a bird, and then inserting that variable into a url api call. I got how to parse and echo the data once I get it, I just can't seem to find anything on setting part of the url as a user defined variable. here's what I have so far

input type="text" name="idtest" value="<?php echo htmlspecialchars($searchbird); ?>" />
$url = "http://ebird.org/ws1.1/data/obs/region_spp/recent?rtype=subnational2&r=US-AZ-013&sci=$searchbird";
$xml = simplexml_load_file($url);

    foreach ($xml->result->location as $location):
        $locname=$location->{'loc-name'};
        $lat=$location->{'lat'};
        $lng=$location->{'lng'};
        $locid=$location->{'loc-id'};
echo " blah blah";
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309

1 Answers1

0

Assuming $searchbird is the user submitted data:

$url = "http://ebird.org/ws1.1/data/obs/region_spp/recent?" . http_build_query(array(
  'rtype' => 'subnational2',
  'r' => 'US-AZ-013',
  'sci' => $searchbird,
));

This will make sure $searchbird is properly escaped inside the constructed URL.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309