3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php header('Content-Type: text/html; charset=UTF-8'); $str = "<h1>He'llü & Wor&#39;ldÆØÅÅÅ!</h1>" . "\tcafé\n"; if ('UTF-8' !== mb_detect_encoding($str)) { $str = utf8_encode($str); } var_dump($str); $str = html_entity_decode($str, ENT_QUOTES | ENT_XML1, 'UTF-8'); var_dump($str); $str = filter_var(html_entity_decode($str, ENT_QUOTES | ENT_XML1, 'UTF-8'), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_NO_ENCODE_QUOTES); var_dump($str); #$newstr = preg_replace('/\s[\s]+/', ' ', $str); // Strip off multiple spaces $newstr = preg_replace('/[^\000-\128]+/', '', $str); // Strip off non-alpha-numeric #$newstr = preg_replace('/[\s\W]+/', '-', $newstr); // Strip off spaces and non-alpha-numeric #$newstr = preg_replace('/[^A-Za-z0-9_-]+/', '', $newstr); var_dump($newstr);
based on p2nYE
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
string(47) "<h1>He'llü & Wor&#39;ldÆØÅÅÅ!</h1> café " string(43) "<h1>He'llü & Wor'ldÆØÅÅÅ!</h1> café " string(18) "He'll & Wor'ld!caf" string(0) ""