3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input_lines = 'This is a test for<img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Girl">my <img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Girl">regex which<img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Girl">should be alright <img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Not-Talking">and<img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Not-Talking"> match all this emoticons except things like <img dsopjfdojp <img oew> because this ones are not real emoticons! The following is a real one: <img src="data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" class="emoticon Girl">'; $doc = new DOMDocument(); // Suppress warnings @$doc->loadHTML($input_lines); $imgs = $doc->getElementsByTagName("img"); $number_of_imgs = $imgs->length; echo "Found $number_of_imgs images" . PHP_EOL; // The plain text is actually the nodeValue of // the whole snippet. $text = $imgs->item(0)->parentNode->nodeValue; $len = mb_strlen($text); echo "Text length: $len + $number_of_imgs(images)" . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MH5T6
function name:  (null)
number of ops:  38
compiled vars:  !0 = $input_lines, !1 = $doc, !2 = $imgs, !3 = $number_of_imgs, !4 = $text, !5 = $len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'This+is+a+test+for%3Cimg+src%3D%22data%3Aimage%2Fgif%3Bbase64%2CR0lGODlhAQABAAAAACwAAAAAAQABAAA%3D%22+class%3D%22emoticon+Girl%22%3Emy+%3Cimg+src%3D%22data%3Aimage%2Fgif%3Bbase64%2CR0lGODlhAQABAAAAACwAAAAAAQABAAA%3D%22+class%3D%22emoticon+Girl%22%3Eregex+which%3Cimg+src%3D%22data%3Aimage%2Fgif%3Bbase64%2CR0lGODlhAQABAAAAACwAAAAAAQABAAA%3D%22+class%3D%22emoticon+Girl%22%3Eshould+be+alright+%3Cimg+src%3D%22data%3Aimage%2Fgif%3Bbase64%2CR0lGODlhAQABAAAAACwAAAAAAQABAAA%3D%22+class%3D%22emoticon+Not-Talking%22%3Eand%3Cimg+src%3D%22data%3Aimage%2Fgif%3Bbase64%2CR0lGODlhAQABAAAAACwAAAAAAQABAAA%3D%22+class%3D%22emoticon+Not-Talking%22%3E+match+all+this+emoticons+except+things+like+%3Cimg+dsopjfdojp+%3Cimg+oew%3E+because+this+ones+are+not+real+emoticons%21+The+following+is+a+real+one%3A+%3Cimg+src%3D%22data%3Aimage%2Fgif%3Bbase64%2CR0lGODlhAQABAAAAACwAAAAAAQABAAA%3D%22+class%3D%22emoticon+Girl%22%3E'
    5     1        NEW                                              $7      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
    8     4        BEGIN_SILENCE                                    ~10     
          5        INIT_METHOD_CALL                                         !1, 'loadHTML'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        END_SILENCE                                              ~10
   10     9        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         10        SEND_VAL_EX                                              'img'
         11        DO_FCALL                                      0  $12     
         12        ASSIGN                                                   !2, $12
   11    13        FETCH_OBJ_R                                      ~14     !2, 'length'
         14        ASSIGN                                                   !3, ~14
   12    15        ROPE_INIT                                     3  ~17     'Found+'
         16        ROPE_ADD                                      1  ~17     ~17, !3
         17        ROPE_END                                      2  ~16     ~17, '+images'
         18        CONCAT                                           ~19     ~16, '%0A'
         19        ECHO                                                     ~19
   16    20        INIT_METHOD_CALL                                         !2, 'item'
         21        SEND_VAL_EX                                              0
         22        DO_FCALL                                      0  $20     
         23        FETCH_OBJ_R                                      ~21     $20, 'parentNode'
         24        FETCH_OBJ_R                                      ~22     ~21, 'nodeValue'
         25        ASSIGN                                                   !4, ~22
   17    26        INIT_FCALL                                               'mb_strlen'
         27        SEND_VAR                                                 !4
         28        DO_ICALL                                         $24     
         29        ASSIGN                                                   !5, $24
   19    30        ROPE_INIT                                     5  ~27     'Text+length%3A+'
         31        ROPE_ADD                                      1  ~27     ~27, !5
         32        ROPE_ADD                                      2  ~27     ~27, '+%2B+'
         33        ROPE_ADD                                      3  ~27     ~27, !3
         34        ROPE_END                                      4  ~26     ~27, '%28images%29'
         35        CONCAT                                           ~30     ~26, '%0A'
         36        ECHO                                                     ~30
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.19 ms | 1015 KiB | 14 Q