I am importing an RSS feed from the NOAA website which is returned as RSS.
The latitude and longitude values are returned as one tag which is below:
<georss:point>40.369 -73.703</georss:point>
Is it possible to 'break' apart these values and create two variables such as:
$lat = 40.369
$lng = -73.703
Here is my PHP script that is currently parsing out the XML:
$rss_title = $RSS_DOC->channel->title;
$rss_link = $RSS_DOC->channel->link;
$rss_editor = $RSS_DOC->channel->managingEditor;
$rss_copyright = $RSS_DOC->channel->copyright;
$rss_date = $RSS_DOC->channel->item->pubDate;
$rss_description = $RSS_DOC->channel->item->description;
Appreciate any resource to get me pointed in the right direction. thanks,
Yes, not too hard. Explode (edited - thanks #sdleihssirhc):
http://php.net/manual/en/function.explode.php
E.g.:
list($latt, $long) = explode(" ", $RSS_DOC->channel->item->point);
Hope it works.
Related
i am looking for some help to find the distance between two address through php
as i can not use the google maps api. so get a way from this post
Distance between two addresses
but i need to know how can send the request using URL pattern
and grab the repose to save them in database.
http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false
thanks for any suggestion.
///////////////
After these answers i am there
$customer_address_url = urlencode($customer_address);
$merchant_address_url = urlencode($merchant_address);
$map_url = "http://maps.google.com/maps/api/directions/xml?origin=".$merchant_address_url."&destination=".$customer_address_url."&sensor=false";
$response_xml_data = file_get_contents($map_url);
$data = simplexml_load_string($response_xml_data);
XML response is visible when i put this url : http://maps.google.com/maps/api/directions/xml?origin=Quentin+Road+Brooklyn%2C+New+York%2C+11234+United+States&destination=550+Madison+Avenue+New+York%2C+New+York%2C+10001+United+States&sensor=false
but can not printing through
echo "<pre>"; print_r($data); exit;
You can try this..
$url = "http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false";
$data = file_get_contents($url);
Now $data contains resulting xml data. You can parse this xml data using..
http://php.net/manual/simplexml.examples.php
use the haversine formula
Also check https://developers.google.com/maps/documentation/distancematrix/
I have this code that gets the IP address and Latitude and Longitude of the user. However I am wanting ti display it on a map if it finds the lat and long.
$theirip = $_SERVER['REMOTE_ADDR'];
$fileinfo = file_get_contents("http://api.easyjquery.com/ips/?ip=".$theirip."&full=true");
This outputs a string like this.
{"IP":"000.000.00.000","continentCode":"Unknown","continentName":"Unknown","countryCode2":"Unknown","COUNTRY":"Unknown","countryCode3":"Unknown","countryName":"Unknown","regionName":"Unknown","cityName":"Unknown","cityLatitude":0,"cityLongitude":0,"countryLatitude":0,"countryLongitude":0,"localTimeZone":"Unknown","localTime":"0"}
I am wanting to retrieve just the cityLatitude and cityLongitude from this. I have researched some and tried some different code.
$lat = $fileinfo -> {"cityLatitude"};
but i'm not quite sure how to go about this. Any help would be appreciated!
What you have there is a JSON string, you can use json_decode to pasre it
$obj = json_decode($fileinfo);
$lat = $obj -> {"cityLatitude"};
its a JSONObject... just use the json_decode() to get data from it
no need to decode the JSON, it should work fine.
trying from here its working just fine...
try using your IP instead of $theirip = $_SERVER['REMOTE_ADDR'];
You're using PHP right? It should be
$info = json_decode($fileinfo);
$citylatitude = $info->cityLatitude;
I'm trying to get a product list for a client from a webservices xml file over to an SQL databse using a little php script, but I can't seem to get it to work.
The relevant code is as follows:
$c = 0;
...
$xml = simplexml_load_file($completeurl);
$listingsArray = $xml->listings->listing;
foreach($listingsArray as $listing){
$addition[0] = $listing[$c]->type;
$addition[1] = $listing[$c]->condition;
//etcetera
c = c + 1;
}
The XML file is formated like:
<inventory>
<listings>
<listing>
//tags for type, condition, etc
</listing>
</listings>
</inventory>
$completeurl is a string that contains the url of the xml file
$addition is an array that's defined earlier in the code
I've been working on this for a while now, but I can't seem to figure out where the error is in my code. The problem that I'm having is that $listingsArray should have close to 100 elements in it, but is constantly coming up with 0. Anybody see what I'm doing wrong?
EDIT: I tried changing
$listingsArray = $xml->listings->listing;
to
$listingsArray = $xml->listings;
But empty strings are still being written to the $addition array. A var_dump of listingsArray show that all of the information is in there, though.
If you want each listing i believe you are going a child too deep.
$listingsArray = $xml->listings->listing;
shoudl be
$listingsArray = $xml->listings;
foreach($listingsArray as $listing){
$addition[0] = $listing[$c]->type;
$addition[1] = $listing[$c]->condition;
//etcetera
}
additionally what is $c? It also helps to post your exact errors. When debugging inserting var_dumps is extremely helpful. If you think the probelm is $listingArray
print it out and see if it contains the data you want.
changing
$listingsArray = $xml->listings->listing;
to
$listingsArray = $xml->listings;
Should solve the issue. You set $listingsArray to the array of listings, then the foreach tries to go down another level
I have looked everywhere to try and get the answer to this simple task to no avail.
I just need to get the lat/long (geotag) from an image. The docs give an example of how to update the GmlPos in the GeoRssWhere. ( http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_php.html ) But how do you just retrieve that info?
I'v tried the below, but I think i'v got something wrong.
$where = new Zend_Gdata_Geo_Extension_GeoRssWhere();
$georeff = $where->point;
can someone help?
The Picasa API returns entities as Zend_Gdata_Photos_PhotoEntry
You can use getGeoRssWhere() to get the geo data:
$geo = $photo->getGeoRssWhere();
I found a great example getting geotag to display photos on a map like I wanted to do. http://picasaphpworkshop.googlecode.com/svn-history/r11/trunk/workshop.php
The part I couldn't figure out was the $where->getPoint()->getPos(); after getting the georsshwere.
Zend_Loader::loadClass('Zend_Gdata_Media_Extension_MediaKeywords');
Zend_Loader::loadClass('Zend_Gdata_Geo_Extension_GeoRssWhere');
Zend_Loader::loadClass('Zend_Gdata_Geo_Extension_GmlPos');
Zend_Loader::loadClass('Zend_Gdata_Geo_Extension_GmlPoint');
Zend_Loader::loadClass('Zend_Gdata_Photos_PhotoEntry');
$picasa = new Zend_Gdata_Photos();
$query = $picasa->newAlbumQuery();
$query->setUser('user#gmail.com');
$query->setAlbumName('MyAlbumNameFromURL');
$feed = $picasa->getAlbumFeed($query);
foreach($feed as $num => $photoEntry){
$where = $photoEntry->getGeoRssWhere();
$lat = $where->getPoint()->getPos();
//$lat = split(" ", $lat); // Split out the space-separated lat
}
echo "GeoReff: " . $lat . "<br />\n";
I need to find the number of indexed pages in google for a specific domain name, how do we do that through a PHP script?
So,
foreach ($allresponseresults as $responseresult)
{
$result[] = array(
'url' => $responseresult['url'],
'title' => $responseresult['title'],
'abstract' => $responseresult['content'],
);
}
what do i add for the estimated number of results and how do i do that?
i know it is (estimatedResultCount) but how do i add that? and i call the title for example this way: $result['title'] so how to get the number and how to print the number?
Thank you :)
I think it would be nicer to Google to use their RESTful Search API. See this URL for an example call:
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:stackoverflow.com&filter=0
(You're interested in the estimatedResultCount value)
In PHP you can use file_get_contents to get the data and json_decode to parse it.
You can find documentation here:
http://code.google.com/apis/ajaxsearch/documentation/#fonje
Example
Warning: The following code does not have any kind of error checking on the response!
function getGoogleCount($domain) {
$content = file_get_contents('http://ajax.googleapis.com/ajax/services/' .
'search/web?v=1.0&filter=0&q=site:' . urlencode($domain));
$data = json_decode($content);
return intval($data->responseData->cursor->estimatedResultCount);
}
echo getGoogleCount('stackoverflow.com');
You'd load http://www.google.com/search?q=domaingoeshere.com with cURL and then parse the file looking for the results <p id="resultStats" bit.
You'd have the resulting html stored in a variable $html and then say something like
$arr = explode('<p id="resultStats"'>, $html);
$bottom = $arr[1];
$middle = explode('</p>', $bottom);
Please note that this is untested and a very rough example. You'd be better off parsing the html with a dedicated parser or matching the line with regular expressions.
google ajax api estimatedResultCount values doesn't give the right value.
And trying to parse html result is not a good way because google blocks after several search.
Count the number of results for site:yourdomainhere.com - stackoverflow.com has about 830k
// This will give you the count what you see on search result on web page,
//this code will give you the HTML content from file_get_contents
header('Content-Type: text/plain');
$url = "https://www.google.com/search?q=your url";
$html = file_get_contents($url);
if (FALSE === $html) {
throw new Exception(sprintf('Failed to open HTTP URL "%s".', $url));
}
$arr = explode('<div class="sd" id="resultStats">', $html);
$bottom = $arr[1];
$middle = explode('</div>', $bottom);
echo $middle[0];
Output:
About 8,130 results
//vKj
Case 2: you can also use google api, but its count is different:
https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=ursitename&callback=processResults
https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:google.com
cursor":{"resultCount":"111,000,000","
"estimatedResultCount":"111000000",