3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function documentNotUTF8($content) { $exprs = array( '#<\?xml[^>]+encoding=([\'"])[Uu][Tt][Ff]-8\1#U', '#<meta\s+(?:(?:http-equiv\s*=\s*([\'"])content-type\1\s*)|(?:content\s*=\s*([\'"])text/html\s*;.*charset\s*=\s*utf-?8.*\2\s*)){2}#Ui', '#<meta[^>]+charset\s*=\s*([\'"])utf-?8\1#Ui', ); foreach ($exprs as $expr) { if ( $match = preg_match($expr, $content) ) { break; } } return (bool) $match; } $content = array( <<<HTML <?xml version="1.0" encoding="utf-8"?> <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<HTML <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF8"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<HTML <?xml version="1.0" encoding="utf-8" bar="baz"?> <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<HTML <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <META CONTENT="text/html; charset=UTF-8" HTTP-EQUIV="Content-Type"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<HTML <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<HTML <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; stuff=things, charset=UTF-8, otherparam=foo"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<HTML <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <META charset="UTF-8"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<HTML <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <META charset="UTF8"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<HTML <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <META foo="bar" charset="UTF8" baz="qux"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<HTML <HTML> <HEAD> <TITLE>PHP Manual</TITLE> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML ); foreach ($content as $str) { var_dump(documentNotUTF8($str)); }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(false)