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";
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
THIS SENTENCE SHOULD BE SELECTED THIS SENTENCE SHOULD BE SELECTED THIS SENTENCE SHOULD BE SELECTED

preferences:
95.63 ms | 1250 KiB | 4 Q