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+){' . $i . ',}?(?<=\.)))[^.]+\.\s*\S/', $sentence, $match)) { echo "Summary {$i}: {$match[1]}\n"; } else { echo "Full text {$i}: {$sentence}\n"; } }
Output for 4.3.0 - 7.2.0
Summary 1: One two three. Summary 2: One two three. Summary 3: One two three. Summary 4: One two three. Four five six. Summary 5: One two three. Four five six. Summary 6: One two three. Four five six. Summary 7: One two three. Four five six. Seven eight nine. Summary 8: One two three. Four five six. Seven eight nine. Summary 9: One two three. Four five six. Seven eight nine. 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.