- substr: documentation ( source)
- array_map: documentation ( source)
- var_dump: documentation ( source)
- substr_replace: documentation ( source)
- implode: documentation ( source)
- explode: documentation ( source)
- strrpos: documentation ( source)
<?php
function doIt(string $line): string {
$pos = strrpos($line, ">");
if ($pos === false) { return $line; }
if ($pos < 4 || substr($line, $pos - 4, 8) === ">>") { 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>>owo >blyat
lolis";
$line2 = "awoo>>owo";
var_dump(doItMultiline($line));
var_dump(doItMultiline($line2));