shamuraq
-
Posts
140 -
Joined
-
Last visited
Posts posted by shamuraq
-
-
can't seem to get this to work...
$num = rand(1,9); do{ $num1digit1 = rand(1,9); }while($num1digit1 = $num); echo $num1digit1;
Any sugestions?
-
Your're sooooooooooooooo right!!!! Thanx mate!!!
-
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); ?>
-
Do u have a more clearer example on what you're trying to do?
-
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?
-
roopurt18, Thank you sooooo much mate... I'll give it a shot.
-
Yeah ur right. the equation part was wrong. My bad. But the math library. Any suggestion? To write my own would take years from now.
-
Hi All,
I need to create this question in my worksheet. How many 1/3 are there in 3 wholes?
So i came out with these:
$ans = (1/3) / 3;
and i got
0.11111111111111
How do i solve this as a fraction?
-
Whoa you guys are pros talking man... so is the function format wrong or the structure in the if() is wrong? Lol.. Sorry guys. Bit slow here...I can't get the function to work. Its blank screen
-
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>'; ?>
-
Its because $lml_1 is produced with rand();
So for 100% exceeding 10,000 is impossible. Sadly, so is vice versa. I have other options but since i am in my transitional state of understanding PHP, i just wanna learn my options.
-
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?
-
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.
-
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?
-
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?
-
Thanx mate. I actually wanted to know the 'nl2br'. Thanx for the xplanation m8...
-
$challenge = str_replace("'","\'",nl2br($_POST['challenge']));
That should fix you up.
Jons, can you explain a bit to me the breakdown of your code? Because when i call it back from MySQL i need to replace it back to its original form...
-
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...
-
I don't know which error you're getting but in the posted coded you're missing the '$' on the output variable.
HAHAHAHA... bingo... guess tt's what happens with 16hrs of work... Thanx mate...
-
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...
-
Wooooohooooooo...
Thanx Patrick... Thanx Crayon Violent !!!
Outstanding help guys...
At least for a dumb wit like me...
-
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
-
Hi all
for($x1 = 0; $x1 < $lebar; $x1++){ $x1 = $x1 + 30; $a = array( '#FFFFFF', '#666666'); $a1 = $a[array_rand($a)]; }
How do i count the number of "#FFFFFF" and "#666666" being output?
Thanx in advance...
-
Thanx mate.... appreciate it
[SOLVED] do while function... help
in PHP Coding Help
Posted
the reason i use the loop is to prevent both the variables from having the same value...