3v4l.org

run code in 300+ PHP versions simultaneously
<?php $DOM = new DOMDocument(); /** * Use internal errors to get around HTML5 warnings */ libxml_use_internal_errors(true); /** * Load in the content, with proper encoding and an `<html>` wrapper required for parsing */ $DOM->loadHTML("<?xml encoding='utf-8' ?><html>C.C. Johnson & Malhotra, P.C. (CCJM) was an integral member of a large Design Team for a 16.5-mile-long Public-Private Partnership (P3) Purple Line Project. The east-west light rail system extends from New Carrollton in PG County, MD to Bethesda in MO County, MD with 21 stations and one short tunnel. CCJM was Engineer of Record (EOR) for the design of eight (8) Bridges and design reviews for 35 transit/highway bridges and over 100 retaining walls of different lengths/types adjacent to bridges and in areas of cut/fill. CCJM designed utility structures for 42,000 LF of relocated water mains and 19,000 LF of relocated sewer mains meeting Washington Suburban Sanitary Commission (WSSC), Md Dept of Transportation (MDOT) MTA, and Local Standards.</html>", LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); /** * Clear errors to get around HTML5 warnings */ libxml_clear_errors(); /** * Initialize XPath */ $XPath = new DOMXPath($DOM); /** * Retrieve all text nodes, except those within scripts */ $text = $XPath->query("//text()[not(parent::script)]"); foreach ($text as $node) { /** * Find all matches, including offset */ preg_match_all("/(C\.? ?C\.?(?:JM| Johnson (?:&|&amp;|&#38;|and) Malhotra)(?: Engineers, LTD\.?|, P\.?C\.?)?)/i", $node->textContent, $matches, PREG_OFFSET_CAPTURE); /** * Wrap each match in appropriate span */ //foreach ($matches as $group) { $group = array_reverse($matches[0]); foreach ($group as $key => $match) { /** * Determine the offset and the length of the match */ $offset = $match[1]; $length = strlen($match[0]); /** * Isolate the match and what comes after it */ $word = $node->splitText($offset); $after = $word->splitText($length); /** * Create the wrapping span */ $span = $DOM->createElement("span"); $span->setAttribute("class", "__brand"); /** * Replace the word with the span, and then re-insert the word within it */ $word->parentNode->replaceChild($span, $word); $span->appendChild($word); //break; // it always errors after the first loop } //} } /** * Save changes, remove unneeded tags */ $content = implode(array_map([$DOM->documentElement->ownerDocument, "saveHTML"], iterator_to_array($DOM->documentElement->childNodes))); echo wordwrap($content);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 69
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 69
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 67
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 67
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 67
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
filename:       /in/kbSQ8
function name:  (null)
number of ops:  92
compiled vars:  !0 = $DOM, !1 = $XPath, !2 = $text, !3 = $node, !4 = $matches, !5 = $group, !6 = $match, !7 = $key, !8 = $offset, !9 = $length, !10 = $word, !11 = $after, !12 = $span, !13 = $content
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $14     'DOMDocument'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $14
    8     3        INIT_FCALL                                               'libxml_use_internal_errors'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                                 
   13     6        INIT_METHOD_CALL                                         !0, 'loadHTML'
          7        SEND_VAL_EX                                              '%3C%3Fxml+encoding%3D%27utf-8%27+%3F%3E%3Chtml%3EC.C.+Johnson+%26+Malhotra%2C+P.C.+%28CCJM%29+was+an+integral+member+of+a+large+Design+Team+for+a+16.5-mile-long+Public-Private+Partnership+%28P3%29+Purple+Line+Project.+The+east-west+light+rail+system+extends+from+New+Carrollton+in+PG+County%2C+MD+to+Bethesda+in+MO+County%2C+MD+with+21+stations+and+one+short+tunnel.+CCJM+was+Engineer+of+Record+%28EOR%29+for+the+design+of+eight+%288%29+Bridges+and+design+reviews+for+35+transit%2Fhighway+bridges+and+over+100+retaining+walls+of+different+lengths%2Ftypes+adjacent+to+bridges+and+in+areas+of+cut%2Ffill.+CCJM+designed+utility+structures+for+42%2C000+LF+of+relocated+water+mains+and+19%2C000+LF+of+relocated+sewer+mains+meeting+Washington+Suburban+Sanitary+Commission+%28WSSC%29%2C+Md+Dept+of+Transportation+%28MDOT%29+MTA%2C+and+Local+Standards.%3C%2Fhtml%3E'
          8        SEND_VAL_EX                                              8196
          9        DO_FCALL                                      0          
   18    10        INIT_FCALL                                               'libxml_clear_errors'
         11        DO_ICALL                                                 
   23    12        NEW                                              $20     'DOMXPath'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $20
   28    16        INIT_METHOD_CALL                                         !1, 'query'
         17        SEND_VAL_EX                                              '%2F%2Ftext%28%29%5Bnot%28parent%3A%3Ascript%29%5D'
         18        DO_FCALL                                      0  $23     
         19        ASSIGN                                                   !2, $23
   30    20      > FE_RESET_R                                       $25     !2, ->69
         21    > > FE_FETCH_R                                               $25, !3, ->69
   34    22    >   INIT_FCALL                                               'preg_match_all'
         23        SEND_VAL                                                 '%2F%28C%5C.%3F+%3FC%5C.%3F%28%3F%3AJM%7C+Johnson+%28%3F%3A%26%7C%26amp%3B%7C%26%2338%3B%7Cand%29+Malhotra%29%28%3F%3A+Engineers%2C+LTD%5C.%3F%7C%2C+P%5C.%3FC%5C.%3F%29%3F%29%2Fi'
         24        FETCH_OBJ_R                                      ~26     !3, 'textContent'
         25        SEND_VAL                                                 ~26
         26        SEND_REF                                                 !4
         27        SEND_VAL                                                 256
         28        DO_ICALL                                                 
   40    29        INIT_FCALL                                               'array_reverse'
         30        FETCH_DIM_R                                      ~28     !4, 0
         31        SEND_VAL                                                 ~28
         32        DO_ICALL                                         $29     
         33        ASSIGN                                                   !5, $29
   41    34      > FE_RESET_R                                       $31     !5, ->67
         35    > > FE_FETCH_R                                       ~32     $31, !6, ->67
         36    >   ASSIGN                                                   !7, ~32
   45    37        FETCH_DIM_R                                      ~34     !6, 1
         38        ASSIGN                                                   !8, ~34
   46    39        FETCH_DIM_R                                      ~36     !6, 0
         40        STRLEN                                           ~37     ~36
         41        ASSIGN                                                   !9, ~37
   51    42        INIT_METHOD_CALL                                         !3, 'splitText'
         43        SEND_VAR_EX                                              !8
         44        DO_FCALL                                      0  $39     
         45        ASSIGN                                                   !10, $39
   52    46        INIT_METHOD_CALL                                         !10, 'splitText'
         47        SEND_VAR_EX                                              !9
         48        DO_FCALL                                      0  $41     
         49        ASSIGN                                                   !11, $41
   57    50        INIT_METHOD_CALL                                         !0, 'createElement'
         51        SEND_VAL_EX                                              'span'
         52        DO_FCALL                                      0  $43     
         53        ASSIGN                                                   !12, $43
   58    54        INIT_METHOD_CALL                                         !12, 'setAttribute'
         55        SEND_VAL_EX                                              'class'
         56        SEND_VAL_EX                                              '__brand'
         57        DO_FCALL                                      0          
   63    58        FETCH_OBJ_R                                      ~46     !10, 'parentNode'
         59        INIT_METHOD_CALL                                         ~46, 'replaceChild'
         60        SEND_VAR_EX                                              !12
         61        SEND_VAR_EX                                              !10
         62        DO_FCALL                                      0          
   64    63        INIT_METHOD_CALL                                         !12, 'appendChild'
         64        SEND_VAR_EX                                              !10
         65        DO_FCALL                                      0          
   41    66      > JMP                                                      ->35
         67    >   FE_FREE                                                  $31
   30    68      > JMP                                                      ->21
         69    >   FE_FREE                                                  $25
   74    70        INIT_FCALL                                               'implode'
         71        INIT_FCALL                                               'array_map'
         72        FETCH_OBJ_R                                      ~49     !0, 'documentElement'
         73        FETCH_OBJ_R                                      ~50     ~49, 'ownerDocument'
         74        INIT_ARRAY                                       ~51     ~50
         75        ADD_ARRAY_ELEMENT                                ~51     'saveHTML'
         76        SEND_VAL                                                 ~51
         77        INIT_FCALL                                               'iterator_to_array'
         78        FETCH_OBJ_R                                      ~52     !0, 'documentElement'
         79        FETCH_OBJ_R                                      ~53     ~52, 'childNodes'
         80        SEND_VAL                                                 ~53
         81        DO_ICALL                                         $54     
         82        SEND_VAR                                                 $54
         83        DO_ICALL                                         $55     
         84        SEND_VAR                                                 $55
         85        DO_ICALL                                         $56     
         86        ASSIGN                                                   !13, $56
   76    87        INIT_FCALL                                               'wordwrap'
         88        SEND_VAR                                                 !13
         89        DO_ICALL                                         $58     
         90        ECHO                                                     $58
         91      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.67 ms | 1409 KiB | 29 Q