fork download
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.  
  6. <title>PhpFiddle Initial Code</title>
  7.  
  8. <script type="text/javascript">
  9. $(function (){
  10.  
  11. });
  12. </script>
  13.  
  14. <style type="text/css">
  15.  
  16. </style>
  17.  
  18. </head>
  19.  
  20. <body>
  21. <pre>
  22. <?php
  23. $lines = array("Off off world on on on world off\n"
  24. , "off world on\n"
  25. , "on on on on\n"
  26. , "on world off\n"
  27. , "off off\n"
  28. , "off world on"
  29. );
  30. $keep = false;
  31. $keepTrailing = true;
  32. $extractions = array();
  33. $current = '';
  34. foreach($lines as $line){
  35. $parts = preg_split('/\bworld\b/i', $line);
  36. $current .= $parts[0];
  37. for ($i = 1; $i<count($parts); $i++){
  38. if ($keep) $extractions[] = $current;
  39. $keep = !$keep;
  40. $current = $parts[$i];
  41. }
  42. }
  43. if ($keep && $keepTrailing)
  44. $extractions[] = $current;
  45. var_dump($extractions);
  46. ?>
  47. </pre>
  48. </body>
  49. </html>
  50.  
  51.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>PhpFiddle Initial Code</title>

<script type="text/javascript">
$(function (){
    
});
</script>

<style type="text/css">
	
</style>

</head>

<body>
	<pre>
array(3) {
  [0]=>
  string(10) " on on on "
  [1]=>
  string(19) " on
on on on on
on "
  [2]=>
  string(3) " on"
}
</pre>
</body>
</html>