To Convert a letter from the input a number

Discussion in 'PHP' started by OPETH, Sep 15, 2007.

  1. #1
    <html>
    <body>
    
    <form action="deneme.php" method="get">
    sayi: <input type="text" name="sayi" /> </br>
    <input type="submit" />
    </form>
    
    <?php
    
    
    $yaz=($_REQUEST['sayi']) ; 
     
    if ( ($yaz<1)  ||  ($yaz>99) )
    
    {
    echo $yaz="Lütfen 1 ile 99 arasinda bir deger giriniz";
    }
    
    else 
    
    
      $on  = array(" ", "10"=>on, "20"=>yirmi, "30"=>otuz, "40"=>kirk, "50"=>elli, "60"=>altmis, "70"=>yetmis, "80"=>seksen, "90"=>doksan);
      $bir = array(" ", "1"=>bir, "2"=>iki, "3"=>uc, "4"=>dort, "5"=>bes, "6"=>alti, "7"=>yedi, "8"=>sekiz, "9"=>dokuz);
    
    $son=substr($on[$yaz],0,10);
     
     echo $son;
    
    ?>
    
    
    </body>
    </html>
    Code (markup):
    "$on + $bir " These variables don't together.For example don't write as "88","99","11".

    What I do to run this program?
     
    OPETH, Sep 15, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    I really don't understand your question, but I see something wrong in your code that might be causing the problem. You have to add curly brackets to the else for multiple statements.
    
    else 
    {
        $on  = array(" ", "10"=>"on", "20"=>"yirmi", "30"=>"otuz", "40"=>"kirk", "50"=>"elli", "60"=>"altmis", "70"=>"yetmis", "80"=>"seksen", "90"=>"doksan");
        $bir = array(" ", "1"=>bir, "2"=>iki, "3"=>uc, "4"=>dort, "5"=>bes, "6"=>alti, "7"=>yedi, "8"=>sekiz, "9"=>dokuz);
    
        $son=substr($on[$yaz],0,10);
     
        echo $son;
    }
    
    PHP:

    And strings have to go between quotes. PHP will consider them constants first otherwise, and leave notices.
     
    nico_swd, Sep 15, 2007 IP
  3. OPETH

    OPETH Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3

    This program already running.But I wanted two variable "$on and $bir" together to read on screen. The program wouldn't you when write "88".
     
    OPETH, Sep 15, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Al arkadaÅŸ ;)
        
        $on  = array(0=>'', 1=>'on', 2=>'yirmi', 3=>'otuz', 4=>'kirk', 5=>'elli', 6=>'altmis', 7=>'yetmis', 8=>'seksen', 9=>'doksan');
        $bir = array(0=>'', 1=>'bir', 2=>'iki', 3=>'uc', 4=>'dort', 5->'bes', 6=>'alti', 7=>'yedi', 8=>'sekiz', 9=>'dokuz');
    
        $son = $on[(int)($yaz/10)] . ' ' . $bir[$yaz-(int)($yaz/10)*10];
     
        echo $son;
    PHP:
     
    krt, Sep 15, 2007 IP
  5. OPETH

    OPETH Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you for help.

    :)
     
    OPETH, Sep 16, 2007 IP