Jump to content

The Little Guy

Members
  • Posts

    6,675
  • Joined

  • Last visited

Posts posted by The Little Guy

  1. I am not sure if this is what your trying to do...

     

    <?php
    $file = "I went back home to see my family as I was studying in China. By the time I arrived home I was so hungry 
    and the weather was cloudy.";
    $words = array("see", "reader", "stud", "China", "cloudy", "hungry", "answer", "el", "prefer");
    $foundWords = array();
    foreach($words as $word){
         $word = preg_quote($word);
         if(preg_match("/$word/i", $file))
              $foundWords[] = $word;
    }
    
    print_r($foundWords);
    ?>

  2.       <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>" >
            <input name="myguess" type="text" value="<?php echo $_POST['myguess']; ?>">
            <input type="hidden" name="allTheGuesses" value = "<?php echo $_POST['allTheGuesses']; ?>">
            <input type="submit" value="GUESS">
          </form>  

  3. I created this function in a class I will be releasing soon (which I am excited about). But this subtracts 2 dates and gives you the number of days.

     

    function datediff($start_date, $end_date, $exact = false){
    if(!is_int($start_date)){
    	if((bool)$exact)
    		$start = strtotime($start_date);
    	else
    		$start = strtotime(date("Y-m-d", strtotime($start_date)));
    }else{
    	$start = $start_date;
    }
    if(!is_int($end_date)){
    	if((bool)$exact)
    		$end = strtotime($end_date);
    	else
    		$end = strtotime(date("Y-m-d", strtotime($end_date)));
    }else{
    	$end = $end_date;
    }
    return ($start - $end) / 60 / 60 / 24;
    }

  4. no, it only checks the unique ones. So if the column "code" is set to unique, it will only check that column on insert. If it finds a duplicate "code" it won't insert anything, otherwise it will insert.

     

    Example:

     

    insert ignore into members (first_name, code) values ('jim', '123');
    -- inserts 1 row
    
    insert ignore into members (first_name, code) values ('joe', '123');
    -- inserts 0 rows
    
    insert ignore into members (first_name, code) values ('jim', '1233');
    -- inserts 1 row

  5. I like my host (See signature (get a discount)).

     

    They are fast and reliable, and for $15 extra dollars you get a vps, and they don't monitor your bandwidth/space (Number Apache requests are monitored on shared servers).

     

    I am currently using 12GB of space and 115GB of bandwidth (for this month). I have not noticed any downtime.

  6. You could do an "INSERT IGNORE" which would ignore duplicate rows.

     

    So, you would need to make the column "code" as either a primary key or a unique key.

     

    <?php
    $sql = null;
    if(isset($_POST['submit'])){
    if(strlen($_POST['code']) == 19 && substr($_POST['code'],0,7) == '5541258')  { 
    	$code = mysql_real_escape_string($_POST['code']);
    	$secret = mysql_real_escape_string($_POST['secret']);
    	$addr = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
    	$sql = mysql_query("INSERT IGNORE INTO table(code,secret,ip,date) VALUES('$code','$secret','$addr',CURDATE())");
    }
    }
    
    if(mysql_affected_rows($sql) == 1){
    Print "<font color='green'>The code will be checked now</font>"; 
    }else{
    Print "<font color='red'>The code is invalid</font>"; 
    }
    ?>

  7. This might work (might as in I don't know how your using the number).

    <?php
    $values = array(
    "Joe is 18 years old",
    "Joe is 13 years old",
    "Joe is 11 years old",
    "Joe is 100 years old"
    );
    foreach($values as $value){
    preg_match("/\d+/", $value, $matches);
    if($matches[0] >= 18){
    	echo "Joe is 18 or older";
    }else{
    	echo "Joe is under 18";
    }
    echo "<br>";
    }
    ?>

     

     

    if you have as specific number, such as $age = 10, then you could just do something like this:

     

    $age = 10;
    if($age >= 18){
    echo "18 or older";
    }else{
    echo "under 18";
    }
    

×
×
  • 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.