3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MLTemplate { protected function escape($string) { return htmlspecialchars($string, ENT_COMPAT, 'UTF-8', true); } public function substr($string, $start, $length = null) { return mb_substr($string, $start, $length, 'UTF-8'); } public function esc_substr($string, $start, $length = null) { $string = $this->escape($string); $string = $this->substr($string, $start, $length); // Make sure we haven't destroyed an html entity of the end of the string. $eos = substr($string, -10); $m = array(); if (preg_match('/&[#a-zA-Z0-9]+$/', $eos, $m)) { $len = strlen($m[0]); $string = $this->substr($string, 0, -$len); } return $string; } } header('Content-Type: text/plain; charset="utf-8"'); $mlt = new MLTemplate(); var_dump($mlt->esc_substr('uasdasdadot"Ellie"', 0, 27));

preferences:
41.55 ms | 402 KiB | 5 Q