PHP code example of amondar-libs / php-state-flow
1. Go to this page and download the library: Download amondar-libs/php-state-flow 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/ */
amondar-libs / php-state-flow example snippets
use Amondar\PhpStateFlow\StateFlow;
StateFlow::getAbbreviation('New York'); // "NY"
StateFlow::getName('ny'); // "New York"
// Regex fragments
$cityRegex = StateFlow::getCityRegex();
preg_match('/^' . $cityRegex . '$/', 'Los Angeles, CA'); // 1
$codes = StateFlow::getAbbreviations();
$count = StateFlow::getCount(); // 48
$names = StateFlow::getNames();
$codeRegex = StateFlow::getAbbreviationsRegex();
$labelRegex = StateFlow::getNamesRegex();
$map = StateFlow::getAbbreviationByNameMap();
$map = StateFlow::getNameByAbbreviationMap();
StateFlow::getAbbreviation('New York'); // "NY"
StateFlow::getAbbreviation(' New York '); // "NY"
StateFlow::getAbbreviation('New York', true); // "ny"
StateFlow::getAbbreviation('NY'); // null
StateFlow::getName('NY'); // "New York"
StateFlow::getName('ny'); // "New York"
StateFlow::getName('NY', true); // "new york"
StateFlow::getName('XX'); // null
$regex = StateFlow::getCityRegex();
preg_match('/^' . $regex . '$/', 'New York, NY'); // 1
preg_match('/^' . $regex . '$/', 'New York, New York'); // 1
preg_match('/^' . $regex . '$/', 'Invalid City, XX'); // 0
$regexWithDefault = StateFlow::getCityRegex(30, 'Anywhere');
preg_match('/^' . $regexWithDefault . '$/', 'Anywhere'); // 1
$regex = StateFlow::getOriginRegex();
preg_match('/^' . $regex . '$/', 'NY'); // 1
preg_match('/^' . $regex . '$/', 'New York, NY'); // 1
preg_match('/^' . $regex . '$/', 'XX'); // 0
// Search all with "n" in name.
StateFlow::search('n');
// [
// 'nc' => 'North Carolina',
// 'ny' => 'New York',
// 'tn' => 'Tennessee',
// ...
// ]
StateFlow::search(' NY ');
// ['ny' => 'New York']
StateFlow::search(' ');
// []
$random = StateFlow::getRandom();
// [
// 'abbreviation' => 'NY',
// 'name' => 'New York',
// ]
StateFlow::normalizeNameKey('New York'); // "new_york"
StateFlow::normalizeNameKey(' West Virginia-State '); // "west_virginia_state"
enum Region: string
{
case NORTH = 'N';
case SOUTH = 'S';
}
use Amondar\PhpStateFlow\StateFlow;
$codes = StateFlow::getAbbreviations(Region::class); // ['NORTH', 'SOUTH']
$names = StateFlow::getNames(Region::class); // ['N', 'S']
$name = StateFlow::getName('north', false, Region::class); // 'N'