Results 1 to 2 of 2
Dec 12, 2010, 22:16 #1
- Join Date
- Feb 2007
- 0 Post(s)
- 0 Thread(s)
I have a string s1. I want to insert newline character for every 100 Maximum characters. The words should not be split.
example, $s1 = "word1 word2 word3 word4 word5.........wordn";
if the 100th character is in middle of the word then the newline character should be inserted at the end of the previous ending word.
suppose 100th character is o in word3 then the newline character should be inserted after word2.
Can someone help me in this?
i could have used wordwrap, sometimes the number of characters in the words are smaller and larger in different lines it does not look nice.
Dec 12, 2010, 22:24 #2PHP Code:
function excerptWrap($string, $desLength, $endChars = '...', $before = '1', $offChar = ' ')
$partialString = substr($string, $desLength, strlen($string));
$endPosition = strpos($partialString, $offChar);
return substr($string, 0, $desLength+$endPosition).$endChars;
$string = substr($string, 0, $desLength);
$endPosition = strrpos($string, $offChar);
return $string = substr($string, 0, $endPosition).$endChars;
echo excerptWrap($s1, 100);