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+(?:(?:name\s*=\s*([\'"])http_equiv\1\s*)|(?:content\s*=\s*([\'"])text/html\s*;.*charset\s*=\s*utf-?8.*\2\s*)){2}#Ui', ); foreach ($exprs as $expr) { if ( $match = preg_match($expr, $content) ) { break; } } return (bool) $match; } $content = array( <<<'HTML' <?xml version="1.0" encoding="foo"?> <HTML> <!-- $Revision: 317718 $ --> <HEAD> <TITLE>PHP Manual</TITLE> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<'HTML' <HTML> <!-- $Revision: 317718 $ --> <HEAD> <TITLE>PHP Manual</TITLE> <META NAME="HTTP_EQUIV" CONTENT="text/html; charset=UTF-8"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<'HTML' <?xml version="1.0" encoding="foo" bar="baz"?> <HTML> <!-- $Revision: 317718 $ --> <HEAD> <TITLE>PHP Manual</TITLE> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<'HTML' <HTML> <!-- $Revision: 317718 $ --> <HEAD> <TITLE>PHP Manual</TITLE> <META CONTENT="text/html; charset=UTF-8" NAME="HTTP_EQUIV"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<'HTML' <HTML> <!-- $Revision: 317718 $ --> <HEAD> <TITLE>PHP Manual</TITLE> <META NAME="HTTP_EQUIV" CONTENT="text/html; charset=UTF-8"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<'HTML' <HTML> <!-- $Revision: 317718 $ --> <HEAD> <TITLE>PHP Manual</TITLE> <META NAME="HTTP_EQUIV" CONTENT="text/html; stuff=things, charset=UTF-8, otherparam=foo"> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML , <<<'HTML' <HTML> <!-- $Revision: 317718 $ --> <HEAD> <TITLE>PHP Manual</TITLE> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML ); foreach ($content as $str) { var_dump(documentNotUTF8($str)); }
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
bool(false) bool(true) bool(false) bool(true) bool(true) bool(true) bool(false)
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_SL, expecting ')' in /in/Zs1XV on line 20
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_SL, expecting ')' in /in/Zs1XV on line 20
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/Zs1XV on line 20
Process exited with code 255.