There's a serious flaw in the code, let's take this $str as an
example, and follow your function:
"456"
When we call replaceNumbers(), the following happens
4 is replaced by "٤" the string becomes "٤56"
then 5 is replaced by "٥" the string becomes "٤٥6"
now the real problem happens! Every instance of 6 is replaced by
"٦" the result is gonna be very messy. Even Ahmad's version is
flawed, because when you replace a 0, it will ruin all the sequences,
instead use the following. I don't recommend the last two, they are
just provided as examples to save you a bit of typing, but they are
horrible in terms of performance or even simple coding rules.
function replaceNumbers($str){
$arNum = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
$inNum = array("٠", "١", "٢", "٣",
"٤",
"٥", "٦", "٧",
"٨", "٩");
return str_replace($arNum, $inNum, $str);
}
function replaceNumbersBaby($str) {
array_walk(range(0,9), create_function('$num',
'$GLOBALS["inNum"][] = "٠".$num.";";') );
return str_replace(range(0,9), $GLOBALS["inNum"], $str);
}
function replaceNumbersRegex($str){
return preg_replace("/(\d)/", 'f$1;', $str);
}
2008/4/28 Ibrahim Y <[EMAIL PROTECTED]>:
> Hello all,
>
> let's have this piece of code
>
> > <?php
> > function replaceNumbers($str){
> > $str = str_replace("0" , "٠" , $str );
> > $str = str_replace("1" , "١" , $str );
> > $str = str_replace("2" , "٢" , $str );
> > $str = str_replace("3" , "٣" , $str );
> > $str = str_replace("4" , "٤" , $str );
> > $str = str_replace("5" , "٥" , $str );
> > $str = str_replace("6" , "٦" , $str );
> > $str = str_replace("7" , "٧" , $str );
> > $str = str_replace("8" , "٨" , $str );
> > $str = str_replace("9" , "٩" , $str );
> > $str = str_replace("Wednesday" , "الأربعاء" , $str );
> > $str = str_replace("July" , "تموز" , $str );
> > return $str;
> > }
> >
> > echo replaceNumbers("Wednesday, 07 July 2008");
> > ?>
> >
>
> The output when invoking the function as follow:
>
> when removing the line in Bold is ( الأربعاء, ٠٧ تموز ٢٠٠٨ ).
> when the line is there the output is (الأربعاء, �٦٦0;٧ تموز
> �٦٦2;�٦٦0;�٦٦0;٨).what I want is to replace English numbers into
> Arabic(hindi) before I display them on the page, is there any better way to
> replace numbers into Arabic.
>
> Ibrahim
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Jordan PHP Users Group" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/JoPHP
http://Jolug.org/
-~----------~----~----~----~------~----~------~--~---