Get latitude and longitude from address PHP

<?php
$country = “IN”;
$state = “Kerala”;
$city = “Kochi”;
$zipcode = “682030”;
$address = “PHPCodez”;

$query_string = “$country+$state+$city+$zipcode+$address”;
$address_encode = urlencode($query_string);
$geocode = ‘http://maps.google.com/maps/geo?q=’.$address_encode.’&output=json&sensor=false’;
$data = file_get_contents($geocode);
$output= json_decode($data);

if($output->Status->code == ‘620’){
sleep(2);
$geocode = ‘http://maps.google.com/maps/geo?q=’.$address_encode.’&output=json&sensor=false’;
$data = file_get_contents($geocode);
$output= json_decode($data);
} elseif ($output->Status->code == ‘602’){
$query_string = “$country+$state”;
$address_encode = urlencode($query_string);
$geocode = ‘http://maps.google.com/maps/geo?q=’.$address_encode.’&output=json&sensor=false’;
$data = file_get_contents($geocode);
$output= json_decode($data);
$longitude_long = $output->Placemark[0]->Point->coordinates[0];
$latitude_lat = $output->Placemark[0]->Point->coordinates[1];
if(($longitude_long == ”) && ($latitude_lat == ”)) {
$query_string = “$country”;
$address_encode = urlencode($query_string);
$geocode = ‘http://maps.google.com/maps/geo?q=’.$address_encode.’&output=json&sensor=false’;
$data = file_get_contents($geocode);
$output= json_decode($data);
}
}

echo $longitude = isset($output->Placemark[0]->Point->coordinates[0])?$output->Placemark[0]->Point->coordinates[0]:”;
echo $latitude = isset($output->Placemark[0]->Point->coordinates[1])?$output->Placemark[0]->Point->coordinates[1]:”;
?>

Short url bit.ly PHP

<?php
public function getBitlyUrl($url)
{

$version=”version=2.0.1”;
$login=”phpcodez”; // Replace with your login
$API=”phpcodez”;// Replace with your API
$bitly = ‘http://api.bit.ly/shorten?”.$version.”&longUrl=’.urlencode($url).’&login=”.$login.”&apiKey=”.$API.”&format=xml’;
$response = file_get_contents($bitly);
$xml = simplexml_load_string($response);
return ‘http://bit.ly/’.$xml->results->nodeKeyVal->hash;

}

?>

Completely disable any caching PHP

<?php
header(“Expires: Tue, 07 Aug 2000 08:00:00 GMT”);
header(“Last-Modified: ” . gmdate(“D, d M Y H:i:s”) . ” GMT”);
header(“Cache-Control: no-store, no-cache, must-revalidate, max-age=0”);
header(“Cache-Control: post-check=0, pre-check=0”, false);
header(“Pragma: no-cache”);
?>

Modify XML node element value php

XML File – test.xml
===============
<?xml version=”1.0″ encoding=”UTF-8″?>
<PHPCodez>
<Update>
<Time>26</Time>
</Update>
</PHPCodez>

 

PHPCode

========

<?php
$xmlFIle    =       “test.xml”;
$xmlString       =  file_get_contents($xmlFIle);
$content=simplexml_load_string($xmlString);
echo $content->Update->Time;
$content->Update->Time = date(“Y-M-d h:i:s”);
$content->asXML($xmlFIle);
?>

current page url php

<?php

function getCurrentPageURL() {
$pageURL = ‘http’;
if ($_SERVER[“HTTPS”] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER[“SERVER_PORT”] != “80”) {
$pageURL .= $_SERVER[“SERVER_NAME”].”:”.$_SERVER[“SERVER_PORT”].$_SERVER[“REQUEST_URI”];
} else {
$pageURL .= $_SERVER[“SERVER_NAME”].$_SERVER[“REQUEST_URI”];
}

return $pageURL;
}

echo getCurrentPageURL();

?>

Encapsulation

Encapsulation is the packing of data and functions into a single component. The features of encapsulation are supported using classes in most object-oriented programming languages, although other alternatives also exist.

Abstract Class vs Interface

1) For abstract class a method must be declared as abstract. Abstract methods doesn’t have any implementation.
For interface all the methods by default are abstract methods only. So one cannot declare variables or concrete methods in interfaces.

2) The Abstract methods can declare with Access modifiers like public, internal, protected. When implementing in subclass these methods must be defined with the same (or a less restricted) visibility.
All methods declared in an interface must be public.

3)Abstract class can contain variables and concrete methods.Interfaces cannot contain variables and concrete methods except constants.

4)A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class.
A class can implement many interfaces and Multiple interface inheritance is possible.

 

Difference Between abstract class and interface PHP

1) For abstract class a method must be declared as abstract. Abstract methods doesn’t have any implementation.
For interface all the methods by default are abstract methods only. So one cannot declare variables or concrete methods in interfaces.

2) The Abstract methods can declare with Access modifiers like public, internal, protected. When implementing in subclass these methods must be defined with the same (or a less restricted) visibility.
All methods declared in an interface must be public.

3)Abstract class can contain variables and concrete methods.Interfaces cannot contain variables and concrete methods except constants.

4)A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class.
A class can implement many interfaces and Multiple interface inheritance is possible.

 

Factory Classes

Factory classes provide an interface for creating families of related objects. Factory classes are useful when the decision of which class to use must be done at run time and cannot be hard coded during development. Factory classes encapsulate the logic needed to decide which subclass to instantiate and so removes this decision from the application, delegating it to the factory.