صفحة 1 من 2 12 الأخيرةالأخيرة
النتائج 1 إلى 15 من 19

الموضوع: حل التفقيط من سالب 999'999'999 الى 999'999'999

  1. حل التفقيط من سالب 999'999'999 الى 999'999'999



    السلام للجميع
    لقد عملت داله تحول الارقام من صيغه الارقام العشريه مثل "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] > || $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 />';
    }
    ?>






    الملفات المرفقة الملفات المرفقة
    __________________
    هلابي افضل المواقع العربية تصميماً
    انصح باستخدام ابونتو


  2. #2
    عضو نشيط جدا
    تاريخ التسجيل
    Sep 2006
    المشاركات
    389


    جميل اخ هلابي
    هناك احد الاعضاء طلب كود كهذا لا اتذكر اسمه
    اتمنى ان يراه ويستفيد
    وشكرا لك على الكود
    :shy:





    __________________
    أرجوا من الجميع ان يسامحوني ، سواء عرفوني أو لم يعرفوني !! ، ارجوا من جميع من قد اكون اسأت اليهم أن يصفحوا عني ، ومن لديهم عندي حقوق أن يطلبوها مني .. جمعنا الله في الجنان .

  3. #3


    أعتقد الأخ مبرمج إنترنت .. مجرد اعتقاد

    شكراً لك استاذ خالد على الكود الرائع وفعلاً رائع ومفيد للغاية ..

    تحياتي
    sBForum





    __________________
    أحمد أبو النصر
    Junior php Developer
    +20166196074

  4. #4
    عضو فعال جدا
    تاريخ التسجيل
    Feb 2004
    المشاركات
    2,307


    ماشاء الله ، جميل جداً ،





    __________________
    بي اتش بي العرب : php-ar.com
    دروس PHP خاص : phpfaq.php-ar.com

    new site : www.naifphp.net/web



  5. السلام
    ان شاء لله الداله مفيدة .. حبيت اقدم شيء مفيد وجديد ...

    وشكراً على التعليقات





    __________________
    هلابي افضل المواقع العربية تصميماً
    انصح باستخدام ابونتو

  6. #6
    عضو فعال
    تاريخ التسجيل
    Nov 2002
    المشاركات
    1,092


    سلام عليكم

    دالة مفيدة و شكراً لك





    __________________
    البريد
    almuslim@gmail.com
    الماسنجر
    muslem@php.net

  7. #7
    عضو فعال جدا
    تاريخ التسجيل
    Jun 2003
    المشاركات
    2,123


    دالة رائعة كانت هناك دالة شبيه لها ولكن لم تكن دقيقة بشكل صحيح .

    جاري الاستخدام .

    شكرا لك .





    __________________
    htaccess بكل بساطة

    الشفرة الموحدة "يونِكود"

    (إن من مفاسد هذه الحضارة أنها تسمي الاحتيال ذكاءً، والانحلال حرية، و"الرذيلة فناً" والاستغلال معونة) - مصطفى السباعي

  8. #8
    عضو نشيط
    تاريخ التسجيل
    Sep 2006
    المشاركات
    83


    جزاك الله خير على هالدالة الرائعة
    مشكووور وماقصرت





    __________________
    رفيع العتيبي .. ستبقى في قلوبنا

    اللهم ابدله دارا خيرا من داره واهلا خيرا من اهله وادخله الجنة واعذه من عذاب القبر ومن عذاب النار .

  9. #9
    عضو جديد
    تاريخ التسجيل
    Sep 2006
    المشاركات
    1


    تسلم اخوي

    الداله هذي من زمان ادور على حل لها

    الله يجزاك خير






  10. #10


    ماشاء الله جهد موفق

    لكني وجدت خطأ بسيط .. 8 = ثمانة ..
    وحاولت أعدلها وهذي الدالة بعد التعديل
    كود 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){ 
                if (
    $numberValue == )
                    
    $textResult .= $def[$numberValue].'ية'
                else 
                    
    $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 
                

                    if (
    $places[1] == )
                    
    $textResult .= ($places[1] != 0) ? $def[$places[1]].(($places[1] > || $places[2] == 1) ? 'ية' '').(($places[2] != 1) ? ' و' ' ') : ''
                    else 
                    
                    
    $textResult .= ($places[1] != 0) ? $def[$places[1]].(($places[1] > || $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 />'

    ?>






    __________________
    موقع رياض القرآن متخصص بالقرآن الكريم
    WwW.Ryadh-Quran.NeT



  11. السلام ..
    ماقصرت ... حلوة .. كيف نسيت ان الثمانيه تحتاج لها "ي" قبل ال"ة" ... حلوه
    وشكراً .. شكلك انت الوحيد الي جرب الدالة و اشتغل عليها .. هاه؟ ويش رأيك في تحسينات اخرى





    __________________
    هلابي افضل المواقع العربية تصميماً
    انصح باستخدام ابونتو

  12. #12
    خبير سيرفرات لينكس
    تاريخ التسجيل
    Mar 1999
    المشاركات
    4,917


    صديقي الدالة جيدة ولكن يعني هل تجدها معقولة ان تقوم ب

    كود PHP:
    for($x 1$x 1000000000$x $x $x){  
        echo 
    makeNumber2Text(-$x).' ('.number_format(-$x).')<br />';  

    تعمل لوب مليون مرة :|








  13. يعطيك الف عافية اخوي جدا دالة في غاية الروعة وتفيد الكثيرين واولهم انا اكيد

    ستتم التجربة ان شاء الله

    ارق سلامي لك





    __________________
    كل مالا يعطى يضيع



  14. يا beshoo ؟؟ شكلك ما جربت البرنامج ؟ لو سمحت جرب وشوف .. و عرف ان الداله تحتاج الى الامر هذا للعمل .. و هو سطر واحد
    كود PHP:

    makeNumber2Text
    ($x); 
    و يا طويل العمر .. لو سمحت شوف الشرط الثالث في ال for loop

    كود PHP:
    $x $x $x
    //not $x++ 
    و نصيحة .. استعمل الداله قبل ان تعمل اي تخمين .. وشكرً





    __________________
    هلابي افضل المواقع العربية تصميماً
    انصح باستخدام ابونتو

  15. #15


    حسب قراءتي للكود فيه مشكلة لما يكون طول الرقم (7) . لو دخلت خمسة مليون (5000000) راح يكون الناتج (خمسة ملايين وصفر).

    فقط تأكد من أن الخانات الأخيرة لا تساوي صفر قبل إضافة جملة العطف (و).

    وأنا لاحظتك تلافيت الحاجة هذي لما يكون طول الرقم (9)





    __________________
    al7amdan AT gmail





المواضيع المتشابهه

ضوابط المشاركة

  • لا تستطيع إضافة مواضيع جديدة
  • لا تستطيع الرد على المواضيع
  • لا تستطيع إرفاق ملفات
  • لا تستطيع تعديل مشاركاتك
  •  

أضف موقعك هنا| اخبار السيارات | حراج | شقق للايجار في الكويت | بيوت للبيع في الكويت | دليل الكويت العقاري | مقروء | شركة كشف تسربات المياه | شركة عزل اسطح بالرياض | عزل فوم بالرياض| عزل اسطح بالرياض | كشف تسربات المياة بالرياض | شركة عزل اسطح بالرياض