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($content)); }
Output for 5.0.4 - 5.1.1, 5.1.3 - 5.2.2, 7.0.0 - 7.1.0
Notice: Undefined variable: Revision in /in/h4OYr on line 23 Notice: Undefined variable: Revision in /in/h4OYr on line 32 Notice: Undefined variable: Revision in /in/h4OYr on line 43 Notice: Undefined variable: Revision in /in/h4OYr on line 52 Notice: Undefined variable: Revision in /in/h4OYr on line 62 Notice: Undefined variable: Revision in /in/h4OYr on line 72 Notice: Undefined variable: Revision in /in/h4OYr on line 82 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false)
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined variable: Revision in /in/h4OYr on line 28 Notice: Undefined variable: Revision in /in/h4OYr on line 38 Notice: Undefined variable: Revision in /in/h4OYr on line 48 Notice: Undefined variable: Revision in /in/h4OYr on line 58 Notice: Undefined variable: Revision in /in/h4OYr on line 68 Notice: Undefined variable: Revision in /in/h4OYr on line 78 Notice: Undefined variable: Revision in /in/h4OYr on line 87 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) bool(false) bool(false)
Output for 5.2.3 - 5.6.28
Notice: Undefined variable: Revision in /in/h4OYr on line 27 Notice: Undefined variable: Revision in /in/h4OYr on line 37 Notice: Undefined variable: Revision in /in/h4OYr on line 47 Notice: Undefined variable: Revision in /in/h4OYr on line 57 Notice: Undefined variable: Revision in /in/h4OYr on line 67 Notice: Undefined variable: Revision in /in/h4OYr on line 77 Notice: Undefined variable: Revision in /in/h4OYr on line 86 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false)
Output for 5.1.2
Notice: Undefined variable: Revision in /in/h4OYr on line 23 Notice: Undefined variable: Revision in /in/h4OYr on line 33 Notice: Undefined variable: Revision in /in/h4OYr on line 45 Notice: Undefined variable: Revision in /in/h4OYr on line 55 Notice: Undefined variable: Revision in /in/h4OYr on line 66 Notice: Undefined variable: Revision in /in/h4OYr on line 77 Notice: Undefined variable: Revision in /in/h4OYr on line 88 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false)
Output for 4.3.3 - 4.4.1, 4.4.3 - 5.0.3
Notice: Undefined variable: Revision in /in/h4OYr on line 23 Notice: Undefined variable: Revision in /in/h4OYr on line 32 Notice: Undefined variable: Revision in /in/h4OYr on line 43 Notice: Undefined variable: Revision in /in/h4OYr on line 52 Notice: Undefined variable: Revision in /in/h4OYr on line 62 Notice: Undefined variable: Revision in /in/h4OYr on line 72 Notice: Undefined variable: Revision in /in/h4OYr on line 82 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false)
Output for 4.4.2
Notice: Undefined variable: Revision in /in/h4OYr on line 23 Notice: Undefined variable: Revision in /in/h4OYr on line 33 Notice: Undefined variable: Revision in /in/h4OYr on line 45 Notice: Undefined variable: Revision in /in/h4OYr on line 55 Notice: Undefined variable: Revision in /in/h4OYr on line 66 Notice: Undefined variable: Revision in /in/h4OYr on line 77 Notice: Undefined variable: Revision in /in/h4OYr on line 88 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false) Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 Warning: preg_match() expects parameter 2 to be string, array given in /in/h4OYr on line 11 bool(false)
Output for 4.3.0 - 4.3.2
Notice: Undefined variable: Revision in /in/h4OYr on line 23 Notice: Undefined variable: Revision in /in/h4OYr on line 32 Notice: Undefined variable: Revision in /in/h4OYr on line 43 Notice: Undefined variable: Revision in /in/h4OYr on line 52 Notice: Undefined variable: Revision in /in/h4OYr on line 62 Notice: Undefined variable: Revision in /in/h4OYr on line 72 Notice: Undefined variable: Revision in /in/h4OYr on line 82 Notice: Array to string conversion in /in/h4OYr on line 11 Notice: Array to string conversion in /in/h4OYr on line 11 bool(false) Notice: Array to string conversion in /in/h4OYr on line 11 Notice: Array to string conversion in /in/h4OYr on line 11 bool(false) Notice: Array to string conversion in /in/h4OYr on line 11 Notice: Array to string conversion in /in/h4OYr on line 11 bool(false) Notice: Array to string conversion in /in/h4OYr on line 11 Notice: Array to string conversion in /in/h4OYr on line 11 bool(false) Notice: Array to string conversion in /in/h4OYr on line 11 Notice: Array to string conversion in /in/h4OYr on line 11 bool(false) Notice: Array to string conversion in /in/h4OYr on line 11 Notice: Array to string conversion in /in/h4OYr on line 11 bool(false) Notice: Array to string conversion in /in/h4OYr on line 11 Notice: Array to string conversion in /in/h4OYr on line 11 bool(false)