Showing posts with label echo. Show all posts
Showing posts with label echo. Show all posts

Monday, August 4, 2014

get title, meta tags info in php

This php script grab title tag and description, keywords meta of specified url with simple php curl function. And show all information in title tag , meta description and meta keywords tags.

<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

function file_get_contents_curl($url)
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

$html = file_get_contents_curl("http://4evertutorials.blogspot.com/");

$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue;
$metas = $doc->getElementsByTagName('meta');

for ($i = 0; $i < $metas->length; $i++)
{
    $meta = $metas->item($i);
    if($meta->getAttribute('name') == 'description')
        $description = $meta->getAttribute('content');
    if($meta->getAttribute('name') == 'keywords')
        $keywords = $meta->getAttribute('content');
}

echo "Title: $title". '

';
echo "Description: $description". '

';
echo "Keywords: $keywords";





?>

Thursday, June 26, 2014

google map latitude longitude php


In this post PHP script convert an address to geocode Latitude/Longitude positioning with Google Maps. In response, you will be get the latitude and longitude details.

For same, you can use following php code.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/


$url = "http://maps.google.com/maps/api/geocode/json?address=West+Bridgford&sensor=false®ion=UK";
$result = file_get_contents($url);
$response = json_decode($result, true);

 
$latitude = $response['results'][0]['geometry']['location']['lat'];
$longitude = $response['results'][0]['geometry']['location']['lng'];
 
echo "Latitude: " . $latitude . " Longitude: " . $longitude;



?>

 

© 2014 4everTutorials. All rights resevered.

Back To Top