السلام للجميع
لقد عملت داله تحول الارقام من صيغه الارقام العشريه مثل "999" الى الارقام بالصيغه الكتابيه (التفقيط) اي "تسع مائه وتسعة وتسعون" ..
الامكانيات:
تحويل الارقام التي بين 999'999'999- الى 999'999'999
الترخيص:
مفتوح المصدر ... يحق لاي شخص ان يستخدم هذة الداله في اي موقع شخصي او تجاري مع عدم مسح الترخيص المكتوب في بدايه الداله .. وعدم نقل الموضوع بدون الاشاره الى المكان الاصلي او الكاتب الاصلي لهذا الموضوع.
التحسينات:
1- اعاده النظر في الشفرة اذا كانت هناك طريقه اسرع او افضل في تنفيذ الدالة
2- اضافة امكانيه التعامل مع العملات
اذا كانت هناك اي مسئلة او خطأ في المخرجات ارجوا اخباري بذالك
وشكراً
كود PHP:
<?php
/*
*
* function name : jmakeNumber2Texts
* Author: Khalid Hilaby, khalid [AT] hilaby.com
* Last modified : 08/08/2006
*
* COPYRIGHT NOTICE :
* Feel free to modify the code of this program to suit your likings.
* but when you do modify this code or use it on your own site or put
* it on a forum, please contribute with a link.
*
*/
function makeNumber2Text($numberValue){
$textResult = ''; // so i can use .=
$numberValue = "$numberValue";
if($numberValue[0] == '-'){
$textResult .= 'سالب ';
$numberValue = substr($numberValue,1);
}
$numberValue = (int) $numberValue;
$def = array( "0" => 'صفر',
"1" => 'واحد',
"2" => 'اثنان',
"3" => 'ثلاث',
"4" => 'اربع',
"5" => 'خمس',
"6" => 'ست',
"7" => 'سبع',
"8" => 'ثمان',
"9" => 'تسع',
"10" => 'عشر',
"11" => 'أحد عشر',
"12" => 'اثنا عشر',
"100" => 'مائة',
"200" => 'مئتان',
"1000" => 'ألف',
"2000" => 'ألفين',
"1000000" => 'مليون',
"2000000" => 'مليونان');
// check for defind values
if(isset($def[$numberValue])) {
// checking for numbers from 2 to 10 :reson = 2 to 10 uses 'ة' at the end
if($numberValue < 11 && $numberValue > 2){
$textResult .= $def[$numberValue].'ة';
}
else{
// the rest of the defined numbers
$textResult .= $def[$numberValue];
}
}
else{
$tensCheck = $numberValue%10;
$numberValue = "$numberValue";
for($x = strlen($numberValue); $x > 0; $x--){
$places[$x] = $numberValue[strlen($numberValue)-$x];
}
switch(count($places)){
case 2: // 2 numbers
case 1: // or 1 number
{
$textResult .= ($places[1] != 0) ? $def[$places[1]].(($places[1] > 2 || $places[2] == 1) ? 'ة' : '').(($places[2] != 1) ? ' و' : ' ') : '';
$textResult .= (($places[2] > 2) ? $def[$places[2]].'ون' : $def[10].(($places[2] != 2) ? '' : 'ون'));
}
break;
case 3: // 3 numbers
{
$lastTwo = (int) $places[2].$places[1];
$textResult .= ($places[3] > 2) ? $def[$places[3]].' '.$def[100] : $def[(int) $places[3]."00"];
if($lastTwo != 0){
$textResult .= ' و'.makeNumber2Text($lastTwo);
}
}
break;
case 4: // 4 numbrs
{
$lastThree = (int) $places[3].$places[2].$places[1];
$textResult .= ($places[4] > 2) ? $def[$places[4]].'ة الاف' : $def[(int) $places[4]."000"];
if($lastThree != 0){
$textResult .= ' و'.makeNumber2Text($lastThree);
}
}
break;
case 5: // 5 numbers
{
$lastThree = (int) $places[3].$places[2].$places[1];
$textResult .= makeNumber2Text((int) $places[5].$places[4]).((((int) $places[5].$places[4]) != 10) ? ' الفاً' : ' الاف');
if($lastThree != 0){
$textResult .= ' و'.makeNumber2Text($lastThree);
}
}
break;
case 6: // 6 numbers
{
$lastThree = (int) $places[3].$places[2].$places[1];
$textResult .= makeNumber2Text((int) $places[6].$places[5].$places[4]).((((int) $places[5].$places[4]) != 10) ? ' الفاً' : ' الاف');
if($lastThree != 0){
$textResult .= ' و'.makeNumber2Text($lastThree);
}
}
break;
case 7: // 7 numbers 1 mill
{
$textResult .= ($places[7] > 2) ? $def[$places[7]].' ملايين' : $def[(int) $places[7]."000000"];
$textResult .= ' و';
$textResult .= makeNumber2Text((int) $places[6].$places[5].$places[4].$places[3].$places[2].$places[1]);
}
break;
case 8: // 8 numbers 10 mill
case 9: // 9 numbers 100 mill
{
$places[9] = (isset($places[9])) ? $places[9] : '';
$firstThree = (int) $places[9].$places[8].$places[7];
$textResult .= makeNumber2Text($firstThree);
$textResult .= ($firstThree < 11) ? ' ملايين ' : ' مليونا ';
if(((int) $places[6].$places[5].$places[4].$places[3].$places[2].$places[1]) != 0){
$textResult .= ' و';
$textResult .= makeNumber2Text((int) $places[6].$places[5].$places[4].$places[3].$places[2].$places[1]);
}
}
break;
default:
{
$textResult = 'هذا رقم كبير .. ';
}
}
}
return $textResult;
}
// للتجربه استخدم هذا
for($x = 1; $x < 1000000000; $x = $x + $x){
echo makeNumber2Text(-$x).' ('.number_format(-$x).')<br />';
}
for($x = 1; $x < 1000000000; $x = $x + $x){
echo makeNumber2Text($x).' ('.number_format($x).')<br />';
}
?>