Advertisement
5ally

(WordPress) Convert numbers to Khmer characters

Mar 5th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. function convert_numbers_to_khmer( $string ) {
  2.     $khmer_numbers = array('០', '១', '២', '៣', '៤', '៥', '៦', '៧', '៨', '៩', '.');
  3.     $english_numbers = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.');
  4.     return str_replace($english_numbers, $khmer_numbers, $string);
  5. }
  6.  
  7. function make_khmer_time( $the_time ) {
  8.     if ( get_bloginfo( 'language' ) == 'km' ) {
  9.         $the_time = convert_numbers_to_khmer( $the_time );
  10.     }
  11.     return $the_time;
  12. }
  13. add_filter( 'get_the_time', 'make_khmer_time' );
  14. add_filter( 'get_the_date', 'make_khmer_time' );
  15. add_filter('comments_number', 'make_khmer_time');
  16.  
  17. function _make_khmer_link_replace_callback( array $matches ) {
  18.     return '<a' . $matches[1] . '>' . convert_numbers_to_khmer( $matches[2] ) . '</a>';
  19. }
  20.  
  21. function make_khmer_link( $link ) {
  22.     if ( get_bloginfo( 'language' ) == 'km' ) {
  23.         $link = preg_replace_callback(
  24.             '#<a(.*?)>(.+?)</a>#',
  25.             '_make_khmer_link_replace_callback',
  26.             $link
  27.         );
  28.     }
  29.     return $link;
  30. }
  31. add_filter('get_archives_link', 'make_khmer_link');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement