Jump to content

phpretard

Members
  • Posts

    821
  • Joined

  • Last visited

    Never

Posts posted by phpretard

  1. I need to convert numbers to text.

     

    The instructions are to "call the convertNumber function"

     

    I would like to be able to post to this, so I thought convertNumber($_POST['theNumber']);

     

    I can't seem to get it to work.  Can anyone read this and help out?

     

     

    
    <?
    /*
    Copyright 2007-2008 Brenton Fletcher. http://bloople[dot]net/num2text
    You can use this freely and modify it however you want.
    */
    function convertNumber($num)
    {
       list($num, $dec) = explode(".", $num);
    
       $output = "";
    
       if($num{0} == "-")
       {
          $output = "negative ";
          $num = ltrim($num, "-");
       }
       else if($num{0} == "+")
       {
          $output = "positive ";
          $num = ltrim($num, "+");
       }
       
       if($num{0} == "0")
       {
          $output .= "zero";
       }
       else
       {
          $num = str_pad($num, 36, "0", STR_PAD_LEFT);
          $group = rtrim(chunk_split($num, 3, " "), " ");
          $groups = explode(" ", $group);
    
          $groups2 = array();
          foreach($groups as $g) $groups2[] = convertThreeDigit($g{0}, $g{1}, $g{2});
    
          for($z = 0; $z < count($groups2); $z++)
          {
             if($groups2[$z] != "")
             {
                $output .= $groups2[$z].convertGroup(11 - $z).($z < 11 && !array_search('', array_slice($groups2, $z + 1, -1))
                 && $groups2[11] != '' && $groups[11]{0} == '0' ? " and " : ", ");
             }
          }
    
          $output = rtrim($output, ", ");
       }
    
       if($dec > 0)
       {
          $output .= " point";
          for($i = 0; $i < strlen($dec); $i++) $output .= " ".convertDigit($dec{$i});
       }
    
       return $output;
    }
    
    function convertGroup($index)
    {
       switch($index)
       {
          case 11: return " decillion";
          case 10: return " nonillion";
          case 9: return " octillion";
          case 8: return " septillion";
          case 7: return " sextillion";
          case 6: return " quintrillion";
          case 5: return " quadrillion";
          case 4: return " trillion";
          case 3: return " billion";
          case 2: return " million";
          case 1: return " thousand";
          case 0: return "";
       }
    }
    
    function convertThreeDigit($dig1, $dig2, $dig3)
    {
       $output = "";
    
       if($dig1 == "0" && $dig2 == "0" && $dig3 == "0") return "";
    
       if($dig1 != "0")
       {
          $output .= convertDigit($dig1)." hundred";
          if($dig2 != "0" || $dig3 != "0") $output .= " and ";
       }
    
       if($dig2 != "0") $output .= convertTwoDigit($dig2, $dig3);
       else if($dig3 != "0") $output .= convertDigit($dig3);
    
       return $output;
    }
    
    function convertTwoDigit($dig1, $dig2)
    {
       if($dig2 == "0")
       {
          switch($dig1)
          {
             case "1": return "ten";
             case "2": return "twenty";
             case "3": return "thirty";
             case "4": return "forty";
             case "5": return "fifty";
             case "6": return "sixty";
             case "7": return "seventy";
             case "8": return "eighty";
             case "9": return "ninety";
          }
       }
       else if($dig1 == "1")
       {
          switch($dig2)
          {
             case "1": return "eleven";
             case "2": return "twelve";
             case "3": return "thirteen";
             case "4": return "fourteen";
             case "5": return "fifteen";
             case "6": return "sixteen";
             case "7": return "seventeen";
             case "8": return "eighteen";
             case "9": return "nineteen";
          }
       }
       else
       {
          $temp = convertDigit($dig2);
          switch($dig1)
          {
             case "2": return "twenty-$temp";
             case "3": return "thirty-$temp";
             case "4": return "forty-$temp";
             case "5": return "fifty-$temp";
             case "6": return "sixty-$temp";
             case "7": return "seventy-$temp";
             case "8": return "eighty-$temp";
             case "9": return "ninety-$temp";
          }
       }
    }
          
    function convertDigit($digit)
    {
       switch($digit)
       {
          case "0": return "zero";
          case "1": return "one";
          case "2": return "two";
          case "3": return "three";
          case "4": return "four";
          case "5": return "five";
          case "6": return "six";
          case "7": return "seven";
          case "8": return "eight";
          case "9": return "nine";
       }
    }
    ?>
    
    
    
    

     

    Thank you

  2. /[(^0-9)]/ thank you for the reply but it didn't work (probably my fault)

     

    $string="12345678";

     

    Here is all of it:

     

    
    elseif(strlen($string) < 
    {
    $alert="<script>alert('Your Password must contain At Least 8 Characters')</script>";
    } 
    
    elseif(!ereg('[^A-Za-z]', $string]))
    {
    $alert="<script>alert('Your Password must contain At Least 1 Letter')</script>";
    }		
    
    elseif(!ereg('/[(^0-9)]/', $string))
    {
    $alert="<script>alert('Your Password must contain At Least 1 Number')</script>";
    }	
    
    

     

    I am sure there is one string for all of this but I cant figure it...

  3. I am trying to check a string for numbers

     

     

     

    This is what I have:

     

    
    $string="password1";
    
    if(!ereg('[^0-9]', $string))
    {
    $alert="<script>alert('Your Password must contain At Least 1 Number')</script>";
    }
    
    

     

    It doesn't work...any thoughts?

     

    Ultimately the password must contain 8 charactors 1 number and 1 letter

     

     

  4. Why does this get stuck?

     

    $level = 1;
    
    while ($level <= 10)
    {
    
    // if I "echo $level" it counts to 10???
    
    $maleQ.$level=mysql_query("select gender, level from athletes where gender='$level' and level='$level' ");
    
    $male.$level=mysql_num_rows($maleQ.$level);
    
    $level++;
    
    }

  5. Why don't you just use a single query with BETWEEN and if you need the number of rows for the values 1-10 you can just use COUNT and GROUP BY level or gender.

     

    That sounds like it will work...I didn't think of it thank you.

     

    I haven't used that type of query before though.

     

    I understand BETWEEN, COUNT, and GROUP but puting them together hurts my brain :)

     

    Do you have an example I can look at?

  6. I am trying to set up a loop that goes up to 10 and changes the query so instead of

     

    
    $male1mQ=mysql_query("select gender, level from athletes where gender='1' and level='1' ");
    $male1=mysql_num_rows($male1Q);
    
    $male2mQ=mysql_query("select gender, level from athletes where gender='2' and level='2' ");
    $male2=mysql_num_rows($male2Q);
    
    

     

    over and over up to 10 ... I am trying to put this in a loop and I'm stuck.

     

    Thank you

  7. That worked!!

     

    But now I get a duplicate for the first one.

     

    Array
    (
        [user] => 1138227
        [athletes] => Array
            (
                [0] => Array
                    (
                        [0] => 4 // <-- row id
                        [1] => 2
                        [2] => 5
                    )
    
                [1] => Array
                    (
                        [0] => 4 // <-- row id
                        [1] => 1
                        [2] => 3
                    )
    
                [2] => Array
                    (
                        [0] => 5 // <-- row id
                        [1] => 1
                        [2] => 3
                    )
    
            )
    
    )

     

    any thoughts?

  8. The idea behind this code is to set multiple arrays as sessions.

     

    Each array should contain 3 variables about the athlete.

     

    I can only get one row to come back and I think it should have a ++ somewhere, I just don't know where???

     

    
    while($athlete=mysql_fetch_assoc($athletearray))
    {
    $id[]=$athlete['id'];
    $level=$athlete['level'];
    $gender=$athlete['gender'];
    
    	foreach($id as $var){
    
    	$_SESSION['athletes'] = array($id, $gender , $level);
    
    	} // end for each
    
                }free($athletearray);
    
    //THIS IS WHAT I GET BUT I KNOW THERE SHOULD BE 2 SEPERATE ARRAYS
    
    Array
    (
        [user] => 1138227
        [athletes] => Array
            (
                [0] => 5 //<-- row id
                [1] => 1
                [2] => 3
            )
    
            )
    
    
    )
    
    
    //I NEED SOMETHING LIKE THIS
    
    Array
    (
        [user] => 1138227
        [athletes] => Array
            (
                [0] => 5 // <-- row id
                [1] => 1
                [2] => 3
            )
            (
                [0] => 4 // <-- row id
                [1] => 2
                [2] => 5
            )
    
    )
    
    
    

     

    Thank you!

  9. Can someone tell me how to display the all the years between date('Y') - 21 in a select box?

    I can add them but can't figure how to subtract them...

     

    It is for a birth year

     

    
    <select class="athlete_input" name="dobY">
    <option><? echo $_POST['dobY']; ?></option>
    <?
    $stop = (int)date('Y') -21;
    for($y = date('Y'); $y < $stop; $y++){
    echo '<option value="'.$y.'">'.$y.'</option>';
    }
    ?>
    </select>
    
    

     

    Thank you!

  10. 
    <?
    
    if (isset($_POST['submit'])){
    
    $sum=$_POST['addend1'] + $_POST['addend1'];
    
    
    }
    
    ?>
    
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Math</title>
    </head>
    
    <body>
    <form action="" method="post">
    <table border="0" width="100%">
    <tr>
    	<td width="72">Addend</td>
    	<td><input type="text" name="addend1" value="<? echo $_POST['addend1']; ?>" size="6" /></td>
    </tr>
    <tr>
    	<td>Addend</td>
    	<td><input type="text" name="addend2" value="<? echo $_POST['addend1']; ?>" size="6" /></td>
    </tr>
    <tr>
    	<td>Sum</td>
    	<td><input type="text" name="sum"  value="<? echo $sum; ?>" size="6" /> 
    	<input type="submit" name="submit" value="Answer" />
    	</td>
    </tr>
    </table>
    </form>
    </body>
    
    </html>
    
    

  11. I do need to pass both...

     

    should the array go into the funtion?

     

    
    function validate_empty($post, $pop) {
    if (empty($_POST['']))
    	{
    	$alert = "<script>alert('$var')</script>";
    	$pass  = "NO";
    	}
    
                  return array('alert'=>$alert,'pass'=>$pass);
    
    }
    
    

  12. Thank for the explination,,,

     

    It works great.

     

    Do you mind if I complicate it a little?

     

    <?php

     

    
    // FUNTION PAGE.PHP
    
    function validate_empty($post, $pop)
    {
    
    if (empty($_POST['']))
    	{
    	$alert = "<script>alert('$var')</script>";
    	$pass  = "NO";
    	}
    
    return $alert;
    return $pass;	
    
    }
    
    ?>
    
    // HTML PAGE.PHP
    
    <?
    
    include ("the page with the functions");
    
    if (isset($_POST['submit']))
    {
    $result = validate_empty("question", "Empty")
    }
    
    ?>
    
    // HTML HERE
    
    <? echo $result; ?>
    
    

     

     

    What do you think about this?

     

    You have no idea how much time this script would save me!

     

  13. 
    // when the form submits
    $update_the_same_row=mysql_unbuffered_query("update books set 
    
    ISBN='".$_POST['ISBN']."', Title='".$_POST['Title']."', Pages='".$_POST['Pages']." 
    
    where row_id='".$_POST['row_id']."' ") or die(mysql_error());
    
    
    // goes in your form
    
    <input type="hidden" name="row_id" value="<? echo $row_id; ?>" />
    
    

     

    Is this what you mean?  It's difficult to understand without the code...

  14. I an trying to validate a form .

     

    
    if (empty($_POST['question'])){ // here is what I usually use
          $alert = "<script>alert('This Work Fine')</script>";
    
    }
    
    I would like the above in a function so I tried this:
    
    ------------------------------------------------------------
    <?php
    
    function validate($var){
       $alert = "<script>alert('$var')</script>";
    
    }
    
    
    if (empty($_POST['question'])){
       validate('The question is Empty');
    
       }
    
    
    
    
    
    echo $alert; 
    
    
    -->
    
    
    The function script is on a different page and included() when the form is submitted.
    
    

     

    Is their something obvious that I am missing?

     

    It doesn't work as a function

  15. I hope the code below explains my problem.

     

    
    $textarea="Here is all the information ® in the text area";
    
    $replace = str_replace("®", "<sup>®</sup>", $textarea); // I can't quite figure how to use this
    
    $new_text="Here is all the information<sup>®</sup> in the text area";
    
    

     

    Any help?

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.