3v4l.org

run code in 300+ PHP versions simultaneously
<?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\s+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> <LINK REL="STYLESHEET" HREF="style.css"> </HEAD> HTML ); foreach ($content as $str) { var_dump(documentNotUTF8($str)); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 10
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/qmTIl
function name:  (null)
number of ops:  12
compiled vars:  !0 = $content, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, <array>
  102     1      > FE_RESET_R                                       $3      !0, ->10
          2    > > FE_FETCH_R                                               $3, !1, ->10
  103     3    >   INIT_FCALL                                               'var_dump'
          4        INIT_FCALL                                               'documentnotutf8'
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
  102     9      > JMP                                                      ->2
         10    >   FE_FREE                                                  $3
  104    11      > RETURN                                                   1

Function documentnotutf8:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
Branch analysis from position: 12
filename:       /in/qmTIl
function name:  documentNotUTF8
number of ops:  16
compiled vars:  !0 = $content, !1 = $exprs, !2 = $expr, !3 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $5      !1, ->12
          3    > > FE_FETCH_R                                               $5, !2, ->12
   12     4    >   INIT_FCALL                                               'preg_match'
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $6      
          8        ASSIGN                                           ~7      !3, $6
          9      > JMPZ                                                     ~7, ->11
   13    10    > > JMP                                                      ->12
   11    11    > > JMP                                                      ->3
         12    >   FE_FREE                                                  $5
   17    13        BOOL                                             ~8      !3
         14      > RETURN                                                   ~8
   18    15*     > RETURN                                                   null

End of function documentnotutf8

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.1 ms | 1390 KiB | 18 Q