vividona Posted March 2, 2010 Share Posted March 2, 2010 $limit = 400; if (strlen($summary) > $limit) $summary = substr($summary, 0, strrpos(substr($summary, 0, $limit), ' ')) . '...'; echo $summary; I am using bbcode in my script but bbcode could not show if I limited my body string. because the end tags of bbcode will cut off. Link to comment https://forums.phpfreaks.com/topic/193858-limit-string-length/ Share on other sites More sharing options...
inversesoft123 Posted March 2, 2010 Share Posted March 2, 2010 <?php $summary = "I am on [url=http://whatever.com/][/url]"; $find = "[url"; $find2 = "[code]"; if (strpos($summary, $find ) { $ends = "/][/url]"; } if (strpos($summary, $find2 ) { $ends2 = " "; } $limit = 15; if (strlen($summary) > $limit) $collective = "$summary $ends $ends2"; $summary = substr($summary, 0, strrpos(substr($collective, 0, $limit), ' ')) . '...'; echo $summary; ?> [/code] Link to comment https://forums.phpfreaks.com/topic/193858-limit-string-length/#findComment-1020295 Share on other sites More sharing options...
vividona Posted March 2, 2010 Author Share Posted March 2, 2010 Thank you inversesoft123 but it doesn't work with me Link to comment https://forums.phpfreaks.com/topic/193858-limit-string-length/#findComment-1020345 Share on other sites More sharing options...
vividona Posted March 2, 2010 Author Share Posted March 2, 2010 any solution? Link to comment https://forums.phpfreaks.com/topic/193858-limit-string-length/#findComment-1020440 Share on other sites More sharing options...
vividona Posted March 8, 2010 Author Share Posted March 8, 2010 any comment? Link to comment https://forums.phpfreaks.com/topic/193858-limit-string-length/#findComment-1022926 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.