DJTim666 Posted September 15, 2007 Share Posted September 15, 2007 On my website, I am using basic tables and everyone knows if you type something like the following it will stretch the table to unbelievable lengths. Word: wert23rtw2tergwergwr83dty5754c7n53yv59t7vn358935yhmc5t735ytn75mcn73v5tv78935hym357tvm9357yhc3579thc4tgciwhomhegmvy2893589t3yvn59357y635nic9n5y I want to know if there is an existing function in PHP to break the word when it gets to a certain length. -- DJ Quote Link to comment https://forums.phpfreaks.com/topic/69416-string-break/ Share on other sites More sharing options...
micah1701 Posted September 15, 2007 Share Posted September 15, 2007 http://us3.php.net/manual/en/function.wordwrap.php Quote Link to comment https://forums.phpfreaks.com/topic/69416-string-break/#findComment-348771 Share on other sites More sharing options...
DJTim666 Posted September 15, 2007 Author Share Posted September 15, 2007 Doesn't work sorry. Never has worked. If you read through that function, it only wraps WORDS in a string . Quote Link to comment https://forums.phpfreaks.com/topic/69416-string-break/#findComment-348777 Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 if(count($_POST[field]=="300")) {echo "this is the max limit";} Quote Link to comment https://forums.phpfreaks.com/topic/69416-string-break/#findComment-348779 Share on other sites More sharing options...
micah1701 Posted September 15, 2007 Share Posted September 15, 2007 Doesn't work sorry. Never has worked. If you read through that function, it only wraps WORDS in a string . i knew it was to good to be true. sorry. Quote Link to comment https://forums.phpfreaks.com/topic/69416-string-break/#findComment-348780 Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 try mine it should count the number of letters in a field then if it equals 300 echo <?php if(count($_POST[field]=="300")) {echo "this is the max limit without doing a break";} else { if(count($_POST[field]=="301")) print "<br>";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/69416-string-break/#findComment-348782 Share on other sites More sharing options...
DJTim666 Posted September 15, 2007 Author Share Posted September 15, 2007 Once again, posting the field will count all the letters in the field. I only want to count a continuous word. Quote Link to comment https://forums.phpfreaks.com/topic/69416-string-break/#findComment-348784 Share on other sites More sharing options...
micah1701 Posted September 15, 2007 Share Posted September 15, 2007 here you go, i figured out a hack. first convert your string to "words" with chunk_split THEN use wordwrap <?php $longstring = "wert23rtw2tergwergwr83dty5754c7n53yv59t7vn358935yhmc5t735ytn75mcn73v5tv78935hym357tvm9357yhc3579thc4tgciwhomhegmvy2893589t3yvn59357y635nic9n5y"; $maxLength = 50; $split = chunk_split($longstring,$maxLength); $wrap = wordwrap($split,$maxLength,"<br>"," "); echo $wrap; ?> Quote Link to comment https://forums.phpfreaks.com/topic/69416-string-break/#findComment-348785 Share on other sites More sharing options...
effigy Posted September 15, 2007 Share Posted September 15, 2007 Doesn't work sorry. Never has worked. If you read through that function, it only wraps WORDS in a string . If you read through, it also mentions a cut argument: string wordwrap ( string $str [, int $width [, string $break [, bool $cut]]] ) Quote Link to comment https://forums.phpfreaks.com/topic/69416-string-break/#findComment-348822 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.