PHP code example of arthurydalgo / zipcode

1. Go to this page and download the library: Download arthurydalgo/zipcode library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arthurydalgo / zipcode example snippets


ZipCode::setCountry('US');

return Response::make(
    ZipCode::find('10006')
);

$z = new PragmaRX\ZipCode\ZipCode;

return $z->find('20250030')->toArray();

$result = ZipCode::find('10006');

$json = $result->toJson();
$array = $result->toArray();

ZipCode::setPreferredWebService('Zippopotamus');

$webService = ZipCode::getWebServiceByName('Zippopotamus');

$webSerivice->setUrl('http://api.zippopotam.ca');

return ZipCode::find('20250030', $webService);

$webService = new PragmaRX\ZipCode\Support\WebService;

$webSerivice->setUrl('http://api.zippopotam.ca');
$webSerivice->setQuery('/%country%/%zip_code%');

ZipCode::addWebService($webService);

ZipCode::setUserAgent('Googlebot/2.1 (+http://www.google.com/bot.html)');

$result = ZipCode::find('0200');

echo $result->getTimer();

$array = ZipCode::getAvailableCountries();

ZipCode::setQueryParameter('geonames_username', 'yourusername');

$result->getWebService();
$result->getCountryName();

Route::any('zipcode', function() {

    echo
        Form::open(array('url' => 'zipcode')) .
        Form::select('country', ZipCode::getAvailableCountries(), Input::get('country')) .
        Form::text('zipcode', Input::get('zipcode')) .
        Form::submit('go!') .
        Form::close();

    if (Input::get('country'))
    {
        ZipCode::setCountry(Input::get('country'));

        ZipCode::setQueryParameter('geonames_username', 'demo');

        echo '<pre>';
        var_dump(ZipCode::find(Input::get('zipcode'))->toArray());
        echo '</pre>';
    }

});

use PragmaRX\ZipCode\Contracts\ZipCode;

class WelcomeController extends Controller {

	public function generateKey(ZipCode $zipcode)
	{
		return $zipcode->find('20250-030');
	}

}

return array(

	...

	'query_parameters' => array(
		'geonames_username' => 'demo',
	)

);