PHP code example of nagoring / jp-address

1. Go to this page and download the library: Download nagoring/jp-address 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/ */

    

nagoring / jp-address example snippets


$pref = Nago\JpAddress\Pref::getInstance();
$pref->idToName(13); // -----> 東京都
$pref->nameToId("北海道"); // -----> 1
$pref->addressToId('奈良県奈良市雑司町406−1'); // ----->29


$city = Nago\JpAddress\City::getInstance();
$address = "鳥取県鳥取市江津730";

//pref_idがほしい
$prefId = $pref->addressToId($address);
$this->assertSame(31, $prefId);

//city_idがほしい
$cityId = $city->prefIdAndAddressToId($prefId, $address);
$this->assertSame(31201, $cityId);

//都道府県市区を取り除いたものがほしい
$this->assertSame('江津730', $city->removePrefAndCityName($address));