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 Link to comment https://forums.phpfreaks.com/topic/62086-solved-taking-a-result-and-splitting-into-numerous-lines/ 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 />'; } ?> Link to comment https://forums.phpfreaks.com/topic/62086-solved-taking-a-result-and-splitting-into-numerous-lines/#findComment-309105 Share on other sites More sharing options...
effigy Posted July 27, 2007 Share Posted July 27, 2007 wordwrap? Link to comment https://forums.phpfreaks.com/topic/62086-solved-taking-a-result-and-splitting-into-numerous-lines/#findComment-309129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.