3v4l.org

run code in 300+ PHP versions simultaneously
<?php $example1 = 'Blah blah blah. THIS SENTENCE SHOULD BE SELECTED [bbcode]'; $example2 = 'THIS SENTENCE SHOULD BE SELECTED [bbcode]'; $example3 = 'A trick sentence. And another. THIS SENTENCE SHOULD BE SELECTED [bbcode]'; function extractSentence($string) { $before = substr($string, 0, strpos($string, '[bbcode]')); return trim(substr($before, strrpos($before, '.')), "\n ."); } echo extractSentence($example1); echo "\n"; echo extractSentence($example2); echo "\n"; echo extractSentence($example3); echo "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CgDB7
function name:  (null)
number of ops:  19
compiled vars:  !0 = $example1, !1 = $example2, !2 = $example3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'Blah+blah+blah.+THIS+SENTENCE+SHOULD+BE+SELECTED+%5Bbbcode%5D'
    5     1        ASSIGN                                                   !1, 'THIS+SENTENCE+SHOULD+BE+SELECTED+%5Bbbcode%5D'
    7     2        ASSIGN                                                   !2, 'A+trick+sentence.+And+another.+THIS+SENTENCE+SHOULD+BE+SELECTED%0A%0A%0A%5Bbbcode%5D'
   19     3        INIT_FCALL                                               'extractsentence'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $6      
          6        ECHO                                                     $6
   20     7        ECHO                                                     '%0A'
   21     8        INIT_FCALL                                               'extractsentence'
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0  $7      
         11        ECHO                                                     $7
   22    12        ECHO                                                     '%0A'
   23    13        INIT_FCALL                                               'extractsentence'
         14        SEND_VAR                                                 !2
         15        DO_FCALL                                      0  $8      
         16        ECHO                                                     $8
   24    17        ECHO                                                     '%0A'
         18      > RETURN                                                   1

Function extractsentence:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CgDB7
function name:  extractSentence
number of ops:  25
compiled vars:  !0 = $string, !1 = $before
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'substr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        INIT_FCALL                                               'strpos'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 '%5Bbbcode%5D'
          7        DO_ICALL                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                         $3      
         10        ASSIGN                                                   !1, $3
   16    11        INIT_FCALL                                               'trim'
         12        INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !1
         14        INIT_FCALL                                               'strrpos'
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 '.'
         17        DO_ICALL                                         $5      
         18        SEND_VAR                                                 $5
         19        DO_ICALL                                         $6      
         20        SEND_VAR                                                 $6
         21        SEND_VAL                                                 '%0A+.'
         22        DO_ICALL                                         $7      
         23      > RETURN                                                   $7
   17    24*     > RETURN                                                   null

End of function extractsentence

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.23 ms | 1024 KiB | 20 Q