fork(1) download
  1. <?php
  2.  
  3. $string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ipsum lorem dolor Curabitur ac risus nunc. Dolor ipsum lorem.';
  4. $string2 = strtolower($string);
  5. $substring = 'lorem ipsum dolor';
  6. //add the first lorem ipsum dolor
  7. $arr = array($substring);
  8.  
  9. //run until the array is full with all possible combinations i.e. 6 (factorial of 3)
  10. for ($i=0; $i<=20; $i++) {
  11. $wordArray = explode(" ",$substring);
  12. shuffle($wordArray);
  13. $randString= implode(" ",$wordArray);
  14.  
  15. //if random string is not equal to any value already in the array, then push
  16. while (! (in_array($randString,$arr)) ) {
  17. array_push($arr,$randString);
  18. }
  19.  
  20. }
  21. //var_dump($arr);
  22.  
  23. //do the matching
  24. $n = sizeof($arr);
  25. for ($q=0; $q<=$n; $q++) {
  26. $sum += substr_count($string2,$arr[$q]);
  27. }
  28.  
  29. echo "Total occurances: ".$sum;
  30.  
  31. ?>
Success #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
Total occurances: 3array(17) {
  ["ru_oublock"]=>
  int(0)
  ["ru_inblock"]=>
  int(0)
  ["ru_msgsnd"]=>
  int(0)
  ["ru_msgrcv"]=>
  int(0)
  ["ru_maxrss"]=>
  int(6160)
  ["ru_ixrss"]=>
  int(0)
  ["ru_idrss"]=>
  int(0)
  ["ru_minflt"]=>
  int(2308)
  ["ru_majflt"]=>
  int(0)
  ["ru_nsignals"]=>
  int(0)
  ["ru_nvcsw"]=>
  int(6)
  ["ru_nivcsw"]=>
  int(12)
  ["ru_nswap"]=>
  int(0)
  ["ru_utime.tv_usec"]=>
  int(12998)
  ["ru_utime.tv_sec"]=>
  int(0)
  ["ru_stime.tv_usec"]=>
  int(6998)
  ["ru_stime.tv_sec"]=>
  int(0)
}
stderr
PHP Notice:  Undefined variable: sum in /home/AlAUXJ/prog.php on line 26
PHP Notice:  Undefined offset: 6 in /home/AlAUXJ/prog.php on line 26
PHP Warning:  substr_count(): Empty substring in /home/AlAUXJ/prog.php on line 26