3v4l.org

run code in 300+ 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:
138.76 ms | 405 KiB | 5 Q