Re: String Split
| From: | John Kaspar | Date: | Mon, 14 Apr 2003 17:17:44 +0000 |
| Subject: | Re: String Split | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143813@lists.php.net to get a copy of this message | ||
Try exploding it with " ", splitting array elements in a foreach, then imploding them back with " ".
$words = explode(" ", $string);
foreach ($words as $index=>$word) {
if ($index<$x) {
$firsts[] = $word;
} else {
$seconds[] = $word;
}
}
$split1 = implode(" ", $firsts);
$split2 = implode(" ", $seconds);
- John
On 4/14/2003 11:35 AM, Erich Kolb wrote:
How do I split a string after X amount of words?