Skip to content

Instantly share code, notes, and snippets.

@dhassanali
Created February 4, 2018 08:29
Show Gist options
  • Save dhassanali/1796599e6d0e455bd0adc44c1d70f73b to your computer and use it in GitHub Desktop.
Save dhassanali/1796599e6d0e455bd0adc44c1d70f73b to your computer and use it in GitHub Desktop.
Convert to arabic digits
<?php
/**
* Created by PhpStorm.
* User: dhassanali
* Date: 12/4/17
* Time: 8:56 PM
*/
class Digit
{
public static function toArabic($str)
{
return str_replace(
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'],
$str
);
}
public static function toEnglish($str)
{
return str_replace(
['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'],
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
$str
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment