Skip to content

Instantly share code, notes, and snippets.

@puncoz
Last active March 16, 2021 07:28
Show Gist options
  • Save puncoz/321ebf58a9dfde9846ae44b0c09f0a9f to your computer and use it in GitHub Desktop.
Save puncoz/321ebf58a9dfde9846ae44b0c09f0a9f to your computer and use it in GitHub Desktop.
PHP Useful Helper functions
function _alphaOnly($value)
{
return preg_replace('/[^[:alnum:]\-\.]/u', '', $value);
}
/**
* @param $number
*
* @return string
*/
function convertEnglishToNepali($number)
{
$mapping = preg_split('//u', "०१२३४५६७८९", null, PREG_SPLIT_NO_EMPTY);
return str_replace(array_keys($mapping), $mapping, $number);
}
/**
* @param $number
*
* @return string
*/
function convertNepaliToEnglish($number)
{
$mapping = preg_split('//u', "०१२३४५६७८९", null, PREG_SPLIT_NO_EMPTY);
return str_replace($mapping, array_keys($mapping), $number);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment