hoopplaya4 Posted August 30, 2009 Share Posted August 30, 2009 Hi, I currently have a string that is well over 100 characters long, and I'm using preg_split to split the array at a whitespace, so that words are not cut in the middle. However, my problem is, that the preg_split is only splitting the first 100 characters, and not any subsequent 100 characters after that. For example: <?php $myString = "This is 350 characters long, let's say"; $split = preg_split('/^(.{0,100})\s/', $myString, 0, PREG_SPLIT_DELIM_CAPTURE); //Notice, I want to split every 100 characters. $array_shift($split); print_r($split); // This outputs something like: Array ( [0] => First 100 characters [1] => All other characters, no matter the length of the string.) I am looking for it split in 100 character increments. Any ideas on how I might fix my preg_replace? Thanks! Link to comment https://forums.phpfreaks.com/topic/172478-preg_split-probably-easy/ Share on other sites More sharing options...
ignace Posted August 30, 2009 Share Posted August 30, 2009 $words = str_word_count($text, 1); print_r($words); Link to comment https://forums.phpfreaks.com/topic/172478-preg_split-probably-easy/#findComment-909306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.