3v4l.org

run code in 300+ PHP versions simultaneously
<?php function doIt(string $line): string { $pos = strrpos($line, "&gt;"); if ($pos === false) { return $line; } if ($pos < 4 || substr($line, $pos - 4, 8) === "&gt;&gt;") { return $line; } return substr_replace($line, '<p style="color:#0f0;">', $pos, 0) . "</p>"; } function doItMultiline(string $owo): string { return implode(array_map('doIt', explode(PHP_EOL, $owo)), PHP_EOL); } $line = "awoo&gt;&gt;owo &gt;blyat lolis"; $line2 = "awoo&gt;&gt;owo"; var_dump(doItMultiline($line)); var_dump(doItMultiline($line2));

preferences:
58.39 ms | 410 KiB | 5 Q