WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : convert a number (three digits) to written form (English & Spanish)
Categories : PHP, Algorithms Update Picture
Felver Alfonzo Yepez Cabrera
Date : Jun 09th 2000
Grade : 3 of 5 (graded 2 times)
Viewed : 19131
File : toString.php
Images : No Images for this code example.
Search : More code by Felver Alfonzo Yepez Cabrera
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This example convert a number of three digits is her equivalent written form... the example
was wrote to convert a number in the spanish and english way... is totally functionally... if you
wanna see the example writting in spanish just comment the arrays for english and
uncomnent the arrays for spanish! enjoy it!

PD: sorry about my english... isn't my native language!!! :)

<?
        #$units = array( 1=>"uno", "dos", "tres", "cuatro", "cinco", "seis",
"siete", "ocho", "nueve" );
        #$dozens = array( 1=>"diez", "veinte", "treinta", "cuarenta", "cincuenta",
"sesenta", "setenta", "ochenta", "noventa" );
        #$hundreds = array( 1=>"cien", "doscientos", "trescientos", "cuatrocientos",
"quinientos", "seiscientos", "setecientos",
"ochocientos", "novecientos" );
        #$dozens_sp = array( 1=>"once", "doce", "trece", "catorce", "quince" );
        
        $units = array( 1=>"one", "two", "three", "four", "five", "six",
"seven", "eigth", "nine" );
        $dozens = array( 1=>"ten", "twenty", "thirty", "fourty", "fifty",
"sixty", "seventy", "eighty", "ninety");
        $dozens_sp = array( 1=>"eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eigthteen", "nineteen");
        
        # Add leading zeros to the number if the length is
        # less than 3, otherwise return the same number! :)
        function LeadingZeros( $number )
        {
                $nz = 3 - strlen( $number );

                if( $nz != 0)
                {
                        if( $nz > 0 )
                        {
                                $nwz = "";
                                for( $i = 0; $i < $nz; $i++ )
                                        $nwz .= "0";
                                $nwz .= $number;
                        }
                        else
                        {
                                $nwz = $number;
                        }
                }
                else
                {
                        $nwz = $number;
                }

                return $nwz;
        }

        # take a number of three digits (in string format) and converts to the
        # equivalent string (in Spanish )
        function Number2String_SP( $number )
        {
                global $units, $dozens, $hundreds, $dozens_sp;
                
                $unt = substr($number, 2, 1);
                $dzn = substr($number, 1, 1);
                $hdd = substr($number, 0, 1);
                
                $iUnt = intval($unt);
                $iDzn = intval($dzn);
                $iHdd = intval($hdd);
                
                // if the Hundreds value is different from zero
                if( $iHdd )
                {
                        if( $iHdd == 1 )
                        {
                                if( ( $iDzn == 0 ) && ( $iUnt == 0 ) )
                                {
                                        $strResult = $hundreds[$iHdd];
                                }
                                else
                                {
                                        $strResult = $hundreds[$iHdd];
                                        $strResult .= "to ";
                                }
                        }
                        else
                        {
                                $strResult = $hundreds[$iHdd];
                                $strResult .= " ";
                        }
                }
                        
                if( $iDzn )
                {
                        if( $iDzn == 1 )
                        {
                                if( $iUnt == 0 )
                                {
                                        $strResult .= $dozens[$iDzn];
                                }
                                else
                                {
                                        if( $iUnt > 0 && $iUnt < 6 )
                                        {
                                                $strResult .= $dozens_sp[$iUnt];
                                        }
                                        else
                                        {
                                                $strResult .= $dozens[$iDzn];
                                                $strResult .= " y ";
                                                $strResult .= $units[$iUnt];
                                        }        
                                }
                        }
                        else
                        {
                                $strResult .= $dozens[$iDzn];
                        }                
                }

                if( $iUnt && ( $iDzn != 1 ) )
                {
                        if($iDzn != 0)
                        {
                                $strResult .= " y ";
                        }
                        else
                        {
                                $strResult .= " ";
                        }
                        
                        $strResult .= $units[$iUnt];
                }
                
                return $strResult;
        }
        
        # take a number of three digits (in string format) and converts to the
        # equivalent string ( in English )
        function Number2String_EN( $number )
        {
                global $units, $dozens, $dozens_sp;
                
                $unt = substr($number, 2, 1);
                $dzn = substr($number, 1, 1);
                $hdd = substr($number, 0, 1);
                
                $iUnt = intval($unt);
                $iDzn = intval($dzn);
                $iHdd = intval($hdd);
                
                // if the Hundreds value is different from zero
                if( $iHdd )
                {
                        $strResult = $units[$iHdd];
                        $strResult .= " hundred ";
                }
                        
                if( $iDzn )
                {
                        if( $iDzn == 1 && $iUnt != 0 )
                        {
                                $strResult .= $dozens_sp[$iUnt];
                        }
                        else
                        {
                                $strResult .= "and ";
                                $strResult .= $dozens[$iDzn];
                                $strResult .= " ";
                        }
                }

                if( $iUnt && ( $iDzn != 1 ) )
                {
                        $strResult .= $units[$iUnt];
                }
                
                return $strResult;
                
        }
?>

<TITLE>Number2String</TITLE>
<BODY>
        <FORM METHOD=POST ACTION="toString.php">
        <INPUT TYPE="Text" NAME= "number">
        <INPUT TYPE="submit" NAME= "submited" VALUE = "Number to String">
        </FORM>
</BODY>

<?
        if($submited)
        {
                $a = Number2String_EN( LeadingZeros( $number ) );
                
                echo $a;
                
        }
?>



minus - subtract arrays. Send two arrays and get an array with the operation A-B, elements on A that are not included on B.
Categories : PHP, Arrays, Algorithms
IPhider Obscure Any URL Anonymity connection lores obfuscation corporate survival.
Categories : PHP, Algorithms, Security, URLs
Browse a MySQL database & draw a tree view & load final items into a template page.
Categories : MySQL, Complete Programs, Algorithms, PHP, Databases
Recursive function to move files on a filesystem. It can be minor changed in order to copy recursively.
Categories : PHP, Filesystem, Algorithms
A simple bubblesort that takes 2 arrays as argument.The first one is the actual data used for sorting, the second is data that will "tag along" with the first array, for instance a descriptive text about the data in the first array.
Categories : Algorithms, Arrays, PHP, Complete Programs
Output database records in multiple table columns. multiple, table, columns, output, format, query output, html table, php
Categories : General SQL, Algorithms, PHP, MySQL
Dollar Serial Number Validator
Categories : PHP, Security, Algorithms
These 2 functions write and read the contents of a specially designated multi-dimensional array to and from a text file.
Categories : Algorithms, PHP, Filesystem
textwrap fill-paragraph (justification)
Categories : Strings, PHP, Algorithms
Function to convert Arabic numbers into Roman Numerals
Categories : Algorithms, PHP, Date Time
Calculate the great circle distance between two latitude/longitudes
Categories : Algorithms, PHP
Diffusion-Limited Aggregation visualization
Categories : PHP, Graphics, Algorithms, Math.
Object() = Custom __autoload + Singleton. "automagically" instantiates a class and always retuns the same instance of the same class. It's pretty useful when you want to have persistence in objects.
Categories : PHP, PHP Classes, Algorithms
Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags.
Categories : PHP, PHP Classes, Algorithms, Security
Reverse a given number
Categories : PHP, Beginner Guides, Algorithms, Math.