Jump to content

shamuraq

Members
  • Posts

    140
  • Joined

  • Last visited

Posts posted by shamuraq

  1. maybe its just sleepless nights trying to get this thing working...

    i made the change "$result[$i] to $arr[$i]"

    and only 1 number came out instead of 6 numbers...

    <?
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    $arr = array();
    $i=0;
    $result = array();
    
    while ( count($arr) < 6 ) {
        $x = mt_rand(1,10);
        if ( !in_array($x,$arr) ) {
    	$arr[$i] = $x;
    	$i+=1;
    }
    }
    print_r($x);
    ?>
    

    :confused:::)

  2. hi all,

     

    I've been trying to source for script to produce unique for digit number as in getting php to randomise 4 digits with no digit having same value.

     

    So i tried this code i got from

    http://forums.digitalpoint.com/showthread.php?t=9048

    and modified it a bit into:

    <?
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    $arr = array();
    $i=0;
    $result = array();
    
    while ( count($arr) < 6 ) {
        $x = mt_rand(1,10);
        if ( !in_array($x,$arr) ) {
    	$result[$i] = $x;
    	$i+=1;
    }
    }
    print_r($x);
    ?>
    

    This is the output that i got:

    Fatal error: Maximum execution time of 30 seconds exceeded in D:\Apache Group\Apache2\htdocs\..... on line 11
    

    Any suggestions?

  3. Hi there,

     

    I'm trying to do a function to get the values of $hour_1,$min_1,$hour_name and $min_name.

    Can anyone help me see what went wrong?

    <? php
    function min2hrmin($hour_1,$min_1,$hour_name,$min_name){
    
    $min = rand(60,999);
    //echo $min.'<br>';
    $hour = $min / 60;
    
    $hour_1 = floor($min / 60);
    	  //Sorting Singular and plural form
    	  if($hour_1 < 1){
    		  $hour_name = 'hour';
    	  }
    	  else{
    		  $hour_name = 'hours';
    	  }
    
    $min_1 = $min % 60;
    	  //Sorting Singular and plural form
    	  if($min_1 < 1){
    		  $min_name = 'minute';
    	  }
    	  else{
    		  $min_name = 'minutes';
    	  }
    return ($hour_1,$min_1,$hour_name,$min_name);	  
    } 
    echo $hour.'<br>';
    echo $min.'<br>';
    echo $hour_1.'<br>';
    echo $min_1.'<br>';
    echo $hour_name.'<br>';
    echo $min_name.'<br>';
    ?>
    

  4. Hi there,

    I try to control the output of this code:

    $multiplier = rand(2,7);
    
    //Get value of second volume via $multiplier
    //Making sure value of second volume is not greater than 10,000 to control array only up to 4
    
    do {
    $lml_2 = $lml_1 * $multiplier;
    } while ($lml_2 > 10000);
    

    and i get this error:

    Fatal error: Maximum execution time of 30 seconds exceeded in volume02.php on line 26
    

    Is there any alternative to the do() while() function?

  5. Your regex does not match against an expression, only a simple pattern, you can use either of these:

    function br2nl($text) {   
          return preg_replace('/<br\\s*?\/??>/i', '', $text);
    }
    br2nl($sub); //Using a function
    
    echo  preg_replace('/<br\\s*?\/??>/i', '', $sub); //Directly
    

    What do u mean my regex doesn't match the expression i thought it clearly state the exact match i want to find and change them specifically. Please do explain. I'm still pretty new to PHP and any explanation that could assist my transition into a better understanding will definitely be of great help. For instance what is regex? I google it but could not understand heads or tails. Apparently there's a lot of problem with regex.

  6. Hi all,

    I'm trying to replace certain characters i pulled from database using preg_replace.

    <?
    $patterns[0] = '<br />';
    $replacements[0] = "\n";
    echo preg_replace($patterns, $replacements, $sub);?>
    ?>
    

    Resulting output:

    Theme 1: Science and Technology<
    >
    Chapter 1	Introducing Science <
    >
    Theme 2: Measurement<
    >
    Chapter 2	Measurement and Units<
    >
    etc.
    

    What i don't understand is why there's "<" and ">" still reflected on the output?

  7. i saw this weird looking example when trying to learn preg_replace() function:

    <?php
    $patterns = array ('/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/',
                       '/^\s*{(\w+)}\s*=/');
    $replace = array ('\3/\4/\1\2', '$\1 =');
    echo preg_replace($patterns, $replace, '{startDate} = 1999-5-27');
    
    ?>
    

    Output:

    5/27/1999
    

    Can anyone pls explain what the jargons in $pattern and $replace means?

     

  8. I have a mix of both <br> and apostrophes in my multiline form entry that i need to send to MySQL BLOB. When i searched online i found that i can use str_replace(). When i tried coding it i realise i can only use it only for either <br> or apostrophe not both.

     

    I tried using mysql_real_escape_string() but nothing was sent to database.

    Below is my current stable script only replacing <br> with "/n". How do i add apostrophe string replace?

    //$challenge=$_POST['challenge'];
    $challenge = str_replace("\n","<br>",$_POST['challenge']);
    //$solutions=$_POST['solutions'];
    $solutions = str_replace("\n","<br>",$_POST['solutions']);
    //$remarks=$_POST['remarks'];
    $remarks = str_replace("\n","<br>",$_POST['remarks']);
    

     

    Thanx in advance...

  9. Hi guys,

    I'm trying to parse HTML form from PHP. Can anyone please tell me what could've gone wrong?

     

    output .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
    output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
    output .= "<head>";
    output .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
    output .= "<link href=\"jjrq.css\" rel=\"stylesheet\" type=\"text/css\" />";
    output .= "</head>";
    output .= "<body>";
    output .= "<form action=\"\" method=\"post\" name=\"table\" id=\"table\">";
    output .= "<select name=\"select\" id=\"select\">";
    output .= "<option value=\"one\">1</option>";
    output .= "<option value=\"two\">2</option>";
    output .= "<option value=\"three\">3</option>";
    output .= "</select>";
    output .= "</form>";
    output .= "</body>";
    output .= "</html>";
    
    print $output;
    

     

    Thanx in advance...

  10. I believe this will do what you're looking for:

     

    $output_counts = array();
    
    for($x1 = 0; $x1 < $lebar; $x1++){
    $x1 = $x1 + 30;
    $a = array( '#FFFFFF', '#666666');
    $a1 = $a[array_rand($a)];
    
    $output_counts[$a1]++;	
    }
    
    print_r($output_counts);

     

    That's exactly what i am looking for but how do i store these results into different variable?

    eg; i want to store

     

    $color1 = count '#FFFFFF';

    $color2 = count '#666666';

     

    Thanx again patrick

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