3v4l.org

run code in 500+ 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:  13
compiled vars:  !0 = $string, !1 = $before
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
   15     1        FRAMELESS_ICALL_2                strpos              ~2      !0, '%5Bbbcode%5D'
          2        FRAMELESS_ICALL_3                substr              ~3      !0, 0
          3        OP_DATA                                                      ~2
          4        ASSIGN                                                       !1, ~3
   16     5        INIT_FCALL                                                   'strrpos'
          6        SEND_VAR                                                     !1
          7        SEND_VAL                                                     '.'
          8        DO_ICALL                                             $5      
          9        FRAMELESS_ICALL_2                substr              ~6      !1, $5
         10        FRAMELESS_ICALL_2                trim                ~7      ~6, '%0A+.'
         11      > RETURN                                                       ~7
   17    12*     > RETURN                                                       null

End of function extractsentence

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
219.67 ms | 1886 KiB | 22 Q