3v4l.org

run code in 500+ PHP versions simultaneously
<?php $str = "string with dot. And another. Again."; $n = 35; // in your case 100 $pos = strrpos(substr($str,0,$n), "."); If($pos === false) $pos = strlen($str); Echo substr($str,0, $pos+1);

preferences:
116.51 ms | 1405 KiB | 5 Q