3v4l.org

run code in 300+ PHP versions simultaneously
<?php function findWord(String $html, String $searchWord): Bool { $dom = new DOMDocument; libxml_use_internal_errors(true); $dom->loadHTML($html); $htmlContent = $dom->getElementsByTagName('body')->item(0); $text = $htmlContent->textContent; return strpos($text, $searchWord) !== false; } // First let's start with html we know the word exists $html = <<<'HTML' <html> <head> <meta content="illustrative productions"> <script> var illustrative = true; </script> <style> .illustrative { background-color: #fff; } </style> </head> <body> <h1 class="illustrative">Hello World</h1> <p>Your search word appears here. <strong>illustrative</strong></p> </body> </html> HTML; // Gives us "Found" if (findWord($html, "illustrative")) { echo "Found"; } else { echo "Not Found"; } // Now let's try HTML we know the word doesn't exist $html = <<<'HTML' <html> <head> <meta content="illustrative productions"> <script> var illustrative = true; </script> <style> .illustrative { background-color: #fff; } </style> </head> <body> <h1 class="illustrative">Hello World</h1> <p>Your search word never appears here.</p> </body> </html> HTML; // Gives us "Not Found" if (findWord($html, "illustrative")) { echo "Found"; } else { echo "Not Found"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
Branch analysis from position: 17
filename:       /in/NpugV
function name:  (null)
number of ops:  19
compiled vars:  !0 = $html
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, '%3Chtml%3E%0A++++%3Chead%3E%0A++++++++%3Cmeta+content%3D%22illustrative+productions%22%3E%0A++++++++%3Cscript%3E%0A++++++++++++var+illustrative+%3D+true%3B%0A++++++++%3C%2Fscript%3E%0A++++++++%3Cstyle%3E%0A++++++++++++.illustrative+%7B%0A++++++++++++++++background-color%3A+%23fff%3B%0A++++++++++++%7D%0A++++++++%3C%2Fstyle%3E%0A++++%3C%2Fhead%3E%0A++++%3Cbody%3E%0A++++++++%3Ch1+class%3D%22illustrative%22%3EHello+World%3C%2Fh1%3E%0A++++++++%3Cp%3EYour+search+word+appears+here.+%3Cstrong%3Eillustrative%3C%2Fstrong%3E%3C%2Fp%3E%0A++++%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   37     1        INIT_FCALL                                               'findword'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'illustrative'
          4        DO_FCALL                                      0  $2      
          5      > JMPZ                                                     $2, ->8
   38     6    >   ECHO                                                     'Found'
   37     7      > JMP                                                      ->9
   40     8    >   ECHO                                                     'Not+Found'
   44     9    >   ASSIGN                                                   !0, '%3Chtml%3E%0A++++%3Chead%3E%0A++++++++%3Cmeta+content%3D%22illustrative+productions%22%3E%0A++++++++%3Cscript%3E%0A++++++++++++var+illustrative+%3D+true%3B%0A++++++++%3C%2Fscript%3E%0A++++++++%3Cstyle%3E%0A++++++++++++.illustrative+%7B%0A++++++++++++++++background-color%3A+%23fff%3B%0A++++++++++++%7D%0A++++++++%3C%2Fstyle%3E%0A++++%3C%2Fhead%3E%0A++++%3Cbody%3E%0A++++++++%3Ch1+class%3D%22illustrative%22%3EHello+World%3C%2Fh1%3E%0A++++++++%3Cp%3EYour+search+word+never+appears+here.%3C%2Fp%3E%0A++++%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   65    10        INIT_FCALL                                               'findword'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 'illustrative'
         13        DO_FCALL                                      0  $4      
         14      > JMPZ                                                     $4, ->17
   66    15    >   ECHO                                                     'Found'
   65    16      > JMP                                                      ->18
   68    17    >   ECHO                                                     'Not+Found'
   69    18    > > RETURN                                                   1

Function findword:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NpugV
function name:  findWord
number of ops:  29
compiled vars:  !0 = $html, !1 = $searchWord, !2 = $dom, !3 = $htmlContent, !4 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        NEW                                              $5      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $5
    5     5        INIT_FCALL                                               'libxml_use_internal_errors'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                                 
    6     8        INIT_METHOD_CALL                                         !2, 'loadHTML'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
    8    11        INIT_METHOD_CALL                                         !2, 'getElementsByTagName'
         12        SEND_VAL_EX                                              'body'
         13        DO_FCALL                                      0  $10     
         14        INIT_METHOD_CALL                                         $10, 'item'
         15        SEND_VAL_EX                                              0
         16        DO_FCALL                                      0  $11     
         17        ASSIGN                                                   !3, $11
   10    18        FETCH_OBJ_R                                      ~13     !3, 'textContent'
         19        ASSIGN                                                   !4, ~13
   12    20        INIT_FCALL                                               'strpos'
         21        SEND_VAR                                                 !4
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $15     
         24        TYPE_CHECK                                  1018  ~16     $15
         25        VERIFY_RETURN_TYPE                                       ~16
         26      > RETURN                                                   ~16
   13    27*       VERIFY_RETURN_TYPE                                       
         28*     > RETURN                                                   null

End of function findword

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.87 ms | 1008 KiB | 17 Q