Jump to content

shamuraq

Members
  • Posts

    140
  • Joined

  • Last visited

About shamuraq

  • Birthday 07/24/1978

Contact Methods

  • MSN
    shamuraq@gmail.com

Profile Information

  • Gender
    Male
  • Location
    Singapore;Indonesia

shamuraq's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. What does the values in 0,5 in substr($v, 0, 5) refers to?
  2. I tried as suggested: $arrFiles = array(); $dirPath = "./"; $files = scandir($dirPath); $required = array_filter($files, fn($v)=>str_starts_with($v, 'alg00')); echo '<pre>' . print_r($required, 1) . '</pre>'; The error: Fatal error: Uncaught Error: Call to undefined function str_starts_with() ...php:29 Stack trace: #0 [internal function]: {closure}('.') #1 /...php(29): array_filter(Array, Object(Closure)) #2 {main} thrown in ...php on line 29
  3. Hi guysm I have a folder containing these files: alg001.php alg002.php alg003.php alg004.php alg005.php algComp.php ranFrac.php ranalg.php randec.php randint.php I would only like to store the names of files alg001.php, alg002.php, alg003.php, alg004.php, alg005.php into an array. How do i achieve this with preg match?
  4. how do i convert the following script to adopt ternary operator to shorten it? $radint = mt_rand(1,33); $flip = mt_rand(1,2); if($flip == 2){ $radint *= -1; } Thanx in advance.
  5. Tes... Thats exactly what i wanted. But can you explain the breakdown of "%-35 = %5d <br>"?
  6. I have a function randomly take 4 unique numbers from an array and multiply them. Problem with the script below is it only print out the products. I would like for each set of 4 numbers and its product to be in its own array and all the arrays into a main array, forming a 2 dimensional array. My current script: //Pruning outcome from controlled lists of Prime Numbers $primes = array(2, 3, 5, 7, 11, 13, 17, 19, 23); function getAllCombinations($arr, $n, $selected = array(), $startIndex = 0) { if ($n == 0) { $product = 1; foreach ($selected as $prime) { $pr[] = $prime; $product *= $prime; $pr[] = $prime; } echo "Product: $product\n"; return; } for ($i = $startIndex; $i < count($arr); $i++) { $selected[] = $arr[$i]; getAllCombinations($arr, $n - 1, $selected, $i + 1); array_pop($selected); // Backtrack and remove the element for next iteration } } getAllCombinations($primes, 4); The output: Product: 210 Product: 330 Product: 390 Product: 510, etc. The preferred method is a 2 dimensional array as such: [0][0] =>2 [0][1] =>3 [0][2]=>5 [0][3]=>7 and the product would be in [0][4] =>210 [1][0] =>2 [1][1] =>3 [1][2]=>5 [1][3]=>11 and the product would be in [1][4] =>330 etc. Any pointers is greatly appreciated.
  7. Hi guys, I am trying to convert randomized float to fractions. For eg; 66.666666666667 = 66 2/3 Any pointers?
  8. Its like this:' $value = array( array(3075,15,461.25,16,535.05), array(3075,15,461.25808,16,535.05),//to be removed array(3075,15,461.2,16,535.05234)//to be removed ); $value = array_filter($value, function ($v) { foreach ($v as $x) { if (strlen(substr(strrchr($x, "."), 1)) > 2) return false; } return true; }); var_dump($value); But nothing came out during testing. What could be wrong?
  9. Hi guys, I am looking fer a way to delete numbers with decimal values more than 2 decimal place in my arrays. Any pointers? Thanx in advance.
  10. Hi guys, am not very good with regex. I need to replace all double backslashes '\\' in my string into single backslashes '\'. I tried: $pattern = '[\\]'; $replacement = '/\/'; ?> <td width="100%"> <?php echo preg_replace($pattern, $replacement,$q[$i]);?></td> i also tried a few other combinations but the output is either blank or more backslashes are added. Any pointers are appreciated. Thanx in advance.
  11. Hi all, I'm trying to list the possible combinations in fraction from 1/1 + 1/1 until 9/9 + 9/9. So i came up with this <?php //numbers of combination for w/x + y/z $num1=1; $den1=1; $num2=1; $den2=1; $row=1; for($w=0; $w<9; $w++){ echo $row.') '; $row=$row+1; echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>'; $num1=$num1+1; for($x=0; $x<9; $x++){ echo $row.') '; $row=$row+1; echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>'; $den1=$den1+1; for($y=0; $y<9; $y++){ echo $row.') '; $row=$row+1; echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>'; $num2=$num2+1; for($z=0; $z<9; $z++){ echo $row.') '; $row=$row+1; echo $num1.'/'.$den1.' + '.$num2.'/'.$den2.'<br>'; $den2=$den2+1; } } } } ?> The problem is it parse all the way to 7380) 10/82 + 730/6561. Where did it go wrong? Thanx in advance...
  12. Solved it... I guess the problem is because am trying to store it in a variable... But i changed to to echo nl2br("$summary"); But am curious tho... Is there anyway to store it in a variable without causing those errors?
  13. Followed ur advice and removed the nl2br from the insert into sql file. But am still getting the same error.
  14. Hi... I read on php.net manual that its better to use str_replace than preg_replace. I used $summary = clean($_POST['summary']); $summary = nl2br($summary); to convert the carriage return(is that the correct term?) to insert them into mysql. So naturally, i want them converted into <br> when i pull them from mysql. I used this: $num_rows=mysql_num_rows($result); if($num_rows == 0){ } else{ for($x = 0; $x < $num_rows; $x++){ $row = mysql_fetch_assoc($result); $id = $row['id']; $position = $row['position']; $summary = $row['summary']; $order = array("\r\n", "\n", "\r"); $replace = '<br />'; $newstr = str_replace($order, $replace, $summary); But i got this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/...php on line 310 Is it a syntax error? Thanx in advance...
  15. thanx .josh. Really appreciate it...
×
×
  • 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.