shlomikalfa Posted November 3, 2008 Share Posted November 3, 2008 This page: http://www.e-lephant.org/Download.php?ID=694 in there you can see the problem, the comments are too long... as i have tried this: $Text = wordwrap($Text, 50, "<br />\n", true); it is not quit what i was looking for... i wanted it to check if the string is without any space for that long then cut if... else, leave it as is.... Any built-in function that does that?! Or should i take the string, split it by spaces, check the length of each and every chunk and then return it ?! Link to comment https://forums.phpfreaks.com/topic/131204-solved-wordwrap-not-quit-it/ Share on other sites More sharing options...
shlomikalfa Posted November 3, 2008 Author Share Posted November 3, 2008 why doesn't this work: function DynWarpText($Text, $HTML1stWrap = -1, $SubWrap = -1){ // Splits the string by spaces ' ', then checks each entry for length. //[$HTML1stWrap:: Instead of trimming it use HTMLwrap and add: '" "'] //[$SubWrap:: Secondaty Wraping size to use after text reaches first size!] $TextArr = explode(" ", $Text); $retText = ""; if ($SubWrap == -1){$SubWrap = $HTML1stWrap;} for ($i = 0; $i <= count($TextArr); $i++){ // Just check the size and split if needed! if (strlen($TextArr[$i]) > $HTML1stWrap){ // If we've reached the size for the first line, we use 2nd line. if (strlen($retText) > $HTML1stWrap){ $retText .= wordwrap($TextArr[$i], $SubWrap, "- ", true)." "; }else { $retText .= wordwrap($TextArr[$i], $HTML1stWrap, " ", true)." "; } }else { $retText .= $TextArr[$i]." "; } } return $retText; } It never switches to the '$SubWrap' Word Wrapping.... Link to comment https://forums.phpfreaks.com/topic/131204-solved-wordwrap-not-quit-it/#findComment-681250 Share on other sites More sharing options...
shlomikalfa Posted November 3, 2008 Author Share Posted November 3, 2008 it appears that: if (strlen($retText) > $HTML1stWrap){ is the issue, since 'strlen($retText)' always returns '0' which is very illogical to me !!! Any idea ?! Link to comment https://forums.phpfreaks.com/topic/131204-solved-wordwrap-not-quit-it/#findComment-681302 Share on other sites More sharing options...
shlomikalfa Posted November 3, 2008 Author Share Posted November 3, 2008 Solved.... For next to come: function DynWarpText($Text, $HTML1stWrap = -1, $SubWrap = -1){ // Splits the string by spaces ' ', then checks each entry for length. //[$HTML1stWrap:: Instead of trimming it use HTMLwrap and add: '" "'] //[$SubWrap:: Secondaty Wraping size to use after text reaches first size!] $TextArr = explode(" ", $Text); $retText = ""; for ($i = 0; $i <= count($TextArr); $i++){ // Just check the size and split if needed! if (strlen($TextArr[$i]) > $HTML1stWrap){ if ($SubWrap > -1){ $retText .= substr($TextArr[$i], 0, $HTML1stWrap)." "; $TextArr[$i] = substr($TextArr[$i], $HTML1stWrap+1); $retText .= wordwrap($TextArr[$i], $SubWrap, "- ", true)." "; }else { $retText .= wordwrap($TextArr[$i], $HTML1stWrap, " ", true)." "; } }else { $retText .= $TextArr[$i]." "; } } return $retText; } Use the above function to form your code if you're using tables and you don't want your tables to go BANANAz... P.S -> Combine with monospaced fonts to make sure your sizes are correct: [#CSS:] #CommentsTd{font: 14px Courier New} Link to comment https://forums.phpfreaks.com/topic/131204-solved-wordwrap-not-quit-it/#findComment-681341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.