3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <p>Zip Code: 99501</p> <p>Part Number: 67001</p> <p>Part Number: 98765 - 10000kg capacity</p> <p>Some dummy/interfering text. Part Number: 12345</p> <p>Zip Codes: 99501, 99524 , 85001 and 72201</p> <p>Part Number: 50545 &ndash; 450g Cartridge 50525 - 2.5kg Tub 50520 - 20kg Pail 50555 - 55kg Drum 50575 *Indent - 175kg Drum</p> HTML; $partnos = []; $dom = new DOMDocument; $dom->loadHTML($html); $xpath = new DOMXPath($dom); foreach ($xpath->query("//p[starts-with(., 'Part Number: ')]") as $node) { // echo "Qualifying text: {$node->nodeValue}\n"; if (preg_match_all('~\b\d{5}\b~', $node->nodeValue, $matches)) { $partnos = array_merge($partnos, $matches[0]); //or array_push($partnos, ...$matches[0]); } } var_export($partnos);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 31
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 31
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 30
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/c2uA8
function name:  (null)
number of ops:  36
compiled vars:  !0 = $html, !1 = $partnos, !2 = $dom, !3 = $xpath, !4 = $node, !5 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Cp%3EZip+Code%3A+99501%3C%2Fp%3E%0A%3Cp%3EPart+Number%3A+67001%3C%2Fp%3E%0A%3Cp%3EPart+Number%3A+98765+-+10000kg+capacity%3C%2Fp%3E%0A%3Cp%3ESome+dummy%2Finterfering+text.+Part+Number%3A+12345%3C%2Fp%3E%0A%3Cp%3EZip+Codes%3A+99501%2C+99524+%2C+85001+and+72201%3C%2Fp%3E%0A%3Cp%3EPart+Number%3A+50545+%26ndash%3B+450g+Cartridge+50525+-+2.5kg+Tub+50520+-+20kg+Pail+50555+-+55kg+Drum+50575+%2AIndent+-+175kg+Drum%3C%2Fp%3E'
   11     1        ASSIGN                                                   !1, <array>
   13     2        NEW                                              $8      'DOMDocument'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $8
   14     5        INIT_METHOD_CALL                                         !2, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
   15     8        NEW                                              $12     'DOMXPath'
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !3, $12
   16    12        INIT_METHOD_CALL                                         !3, 'query'
         13        SEND_VAL_EX                                              '%2F%2Fp%5Bstarts-with%28.%2C+%27Part+Number%3A+%27%29%5D'
         14        DO_FCALL                                      0  $15     
         15      > FE_RESET_R                                       $16     $15, ->31
         16    > > FE_FETCH_R                                               $16, !4, ->31
   18    17    >   INIT_FCALL                                               'preg_match_all'
         18        SEND_VAL                                                 '%7E%5Cb%5Cd%7B5%7D%5Cb%7E'
         19        FETCH_OBJ_R                                      ~17     !4, 'nodeValue'
         20        SEND_VAL                                                 ~17
         21        SEND_REF                                                 !5
         22        DO_ICALL                                         $18     
         23      > JMPZ                                                     $18, ->30
   19    24    >   INIT_FCALL                                               'array_merge'
         25        SEND_VAR                                                 !1
         26        FETCH_DIM_R                                      ~19     !5, 0
         27        SEND_VAL                                                 ~19
         28        DO_ICALL                                         $20     
         29        ASSIGN                                                   !1, $20
   16    30    > > JMP                                                      ->16
         31    >   FE_FREE                                                  $16
   22    32        INIT_FCALL                                               'var_export'
         33        SEND_VAR                                                 !1
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
276.64 ms | 1017 KiB | 16 Q