3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $sentence = "One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen."; for ($i = 1; $i <= 15; $i++) { if (preg_match('/^((\s*\S+){45}(\s*\S+)*?\.).*?\.\s*\S/', $sentence, $match)) { echo "Summary {$i}: {$match[1]}\n"; } else { echo "Full text {$i}: {$sentence}\n"; } }
Output for 5.3.12 - 7.2.0
Full text 1: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 2: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 3: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 4: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 5: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 6: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 7: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 8: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 9: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 10: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 11: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 12: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 13: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 14: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen. Full text 15: One two three. Four five six. Seven eight nine. Ten eleven twelve. Thirteen fourteen fifteen.