Last active
August 29, 2022 12:50
-
-
Save farhadhp/a097c524d054c3c49d04663ca4d69d0d to your computer and use it in GitHub Desktop.
تبدیل اعداد فارسی به اعداد لاتین و بالعکس در php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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