macinslaw Posted July 27, 2007 Share Posted July 27, 2007 I am looking for a way to ake a result and split that result of varchar characters into 2 lines of 16 characters each. For example, if I have the following as a result: "My dog has fleas and ticks." I would want it to display as: "My dog has fleas" " and ticks." Any help would be appreciated. -Mac Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 27, 2007 Share Posted July 27, 2007 You could cycle through the string character by character, adding a new line every 16th character: <?php $str = "My dog has fleas and ticks."; for($x=0;$x<strlen($str);$x++){ $newstr .= $str[$x]; if($x % 16 == 0 && $x != 0){ $newstr .= '<br />'; } } echo $newstr; ?> Edit: If you are using PHP 5, you can use the str_split function: <?php $str = "My dog has fleas and ticks."; $str = str_split($str,16); foreach($str as $v){ echo $v.'<br />'; } ?> Quote Link to comment Share on other sites More sharing options...
effigy Posted July 27, 2007 Share Posted July 27, 2007 wordwrap? Quote Link to comment 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.