- var_dump: documentation ( source)
- mb_strcut: documentation ( source)
<?php
class Foo
{
public $pos = 0;
public $str;
public function __construct($str)
{
$this->str = $str;
$this->current = $this->lookAhead();
}
function isLineBreak()
{
if ("\r" !== $this->current && "\n" !== $this->current) {
return false;
}
$char = $this->current;
do {
$brk = ("\n" === $char);
$char = $this->lookAhead();
switch ($char) {
case " ":
return false;
case "\n":
if ($brk) {
return true;
}
break;
default:
return $brk;
}
} while (true);
}
function lookAhead()
{
return mb_strcut($this->str, $this->pos++, 1);
}
}
function crlf($str)
{
$foo = new Foo($str);
return $foo->isLineBreak();
}
var_dump(crlf("\r\n"));