Skip to content

Instantly share code, notes, and snippets.

@farhadhp
Last active August 29, 2022 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farhadhp/a097c524d054c3c49d04663ca4d69d0d to your computer and use it in GitHub Desktop.
Save farhadhp/a097c524d054c3c49d04663ca4d69d0d to your computer and use it in GitHub Desktop.
تبدیل اعداد فارسی به اعداد لاتین و بالعکس در php
<?php
/**
* Author: Farhad Hassan Pour
* Author Url: https://farhadhp.ir
* Description: Convert Latin numbers to persian number
*/
function convert_numbers_to_persian($srting,$toPersian=true)
{
$en_num = array('0','1','2','3','4','5','6','7','8','9');
$fa_num = array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹');
if( $toPersian ) return str_replace($en_num, $fa_num, $srting);
else return str_replace($fa_num, $en_num, $srting);
}
// Example
echo convert_numbers_to_persian('۰۹۱۲۳۱۲۳۱۲۳۱۲۳', false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment