PHP: split
- Started
- Last post
- 8 Responses
- enobrev0
explode is good..
$my_string = 'The sentence I want to break down into the first six words.';l
$split_sting = explode(' ', $my_string);
$first_six = '';
for($i = 0; $i < 6; $i++) {
$first_siz .= $split_string[$i];
}----
There's also a way of doing it in regex (preg or ereg functions), although I don't remember the pattern, and I don't remember where I have it.
good luck.
- cosmo0
got to work, I used explode.
explode the string, and run a loop through the first 6 words in the array. The easiest way I could think of.
- Mimio0
If you use Quotations (" ") with nothing it will count the spaces I believe.
- cosmo0
thanks guys!
- tomkat0
uuups.. that would be the first 6 letters.. but figure out here
http://www.php.net/substr
- tomkat0
$string = substr($string,0,6)+"...";
- ldww0
i know how to do it with the first 6 characters...
- cosmo
is there a way I can split a string
"Say something like this, which is indeed very long and annoying."
, where I only want to show the first 6 words. Any functions you guys know of.