3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "The time is over. # its mean I'm need to die. Please help me. # Ghost. I am here alone. Sorry. # help yourself."; function lines(string $str): generator { $hPos = strpos($str, "#"); if($hPos !== false) { $dPos = strpos($str, ".", $hPos); if($dPos !== false) { yield substr($str, $hPos + 1, $dPos - $hPos - 1); foreach(lines(substr($str, $dPos + 1)) as $line) { yield $line; } } } } foreach(lines($str) as $line) { printf("%s\n", $line); }

preferences:
27.06 ms | 402 KiB | 5 Q