aebstract Posted February 22, 2010 Share Posted February 22, 2010 I was wondering if anyone knew of a better/shorter/cleaner way to do the following: $article = substr($article, 0, 1000); $dotpos = strrpos($article, '.'); $article = substr($article, 0, $dotpos) . '..'; Basically shortens the string down to 1000 characters, then finds the last period in the string, shortens it down again to that period and then adds .. on the end. I bet there is a way to do it in 1 line? Link to comment https://forums.phpfreaks.com/topic/192947-a-better-way-to-do-this/ Share on other sites More sharing options...
Wolphie Posted February 22, 2010 Share Posted February 22, 2010 I can't really see a shorter way except concatenating it into a single string. Link to comment https://forums.phpfreaks.com/topic/192947-a-better-way-to-do-this/#findComment-1016146 Share on other sites More sharing options...
aebstract Posted February 22, 2010 Author Share Posted February 22, 2010 I figured there would be a way to use a regular expression to start from the 1000th character, go backwards until you run in to a period and then cut it to that point and add 2 more periods. Maybe? Link to comment https://forums.phpfreaks.com/topic/192947-a-better-way-to-do-this/#findComment-1016151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.