musclehead Posted February 1, 2008 Share Posted February 1, 2008 I have a script that churns out a string of variables and is displayed on the page. If this string length is within a certain amount of characters, it is displayed, plain and simple. However, if the string length is > 100 characters, I want to be able to insert a line break (without breaking a word in the string) to avoid clipping data. Example: $myString = "This is a string, that, for the sake of argument, will be more than the 100-character threshold"; if (str_len($myString) > 100){ ... That's where I'm stuck - I want to be able to split the string in half without risking a word being cut in-half or breaking grammar. Any ideas? Link to comment https://forums.phpfreaks.com/topic/88952-solved-split-string-in-middle-and-preserve-string/ Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 PHP already thought of that: http://us3.php.net/manual/en/function.wordwrap.php Link to comment https://forums.phpfreaks.com/topic/88952-solved-split-string-in-middle-and-preserve-string/#findComment-455584 Share on other sites More sharing options...
musclehead Posted February 1, 2008 Author Share Posted February 1, 2008 Ugh...15 lines of make-shift code and outright abuse of the strlen, substr and split functions and I had it working...thanks! Link to comment https://forums.phpfreaks.com/topic/88952-solved-split-string-in-middle-and-preserve-string/#findComment-455594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.