shortysbest Posted January 20, 2011 Share Posted January 20, 2011 How could I split a string in half but not in the middle of a word? $information = "This is the string of text, however at some point in the sentence a word may get split in half."; $cut = round(strlen($information)/2); ///where to cut (50%) $split1 = substr($information, 0, $cut); //first half $split2 = substr($information, $cut); // second half Link to comment https://forums.phpfreaks.com/topic/225094-split-a-string-at-a-certain-number-of-characters-but-not-in-the-middle-of-a-word/ Share on other sites More sharing options...
ignace Posted January 20, 2011 Share Posted January 20, 2011 $estimatedSplit=2; $string='foo bar'; echo substr($string, 0, strpos($string, ' ', $estimatedSplit)); Link to comment https://forums.phpfreaks.com/topic/225094-split-a-string-at-a-certain-number-of-characters-but-not-in-the-middle-of-a-word/#findComment-1162576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.