<?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);
}
- Output for 7.0.33, 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- its mean I'm need to die
Ghost
help yourself
- Output for 5.6.38
- Parse error: syntax error, unexpected ':', expecting '{' in /in/Z8F20 on line 4
Process exited with code 255.
preferences:
164.01 ms | 401 KiB | 179 Q