Jump to content

Split a string at a certain number of characters but not in the middle of a word


shortysbest

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.