Re: Splitting string
| From: | Larry Garfield | Date: | Sun, 10 Dec 2006 09:21:50 +0000 |
| Subject: | Re: Splitting string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-245685@lists.php.net to get a copy of this message | ||
I think the easiest way, if you can guarantee exactly 50 spaces as the
separator, is to simply explode() it.
$string = "EVOLUTION DEAR GOD
BOYZ_II_MEN ";
$arr = explode(str_repeat(' ', 50), $string);
You could also use a regex, but that's probably overkill if your separator is
that simple. If it's not, then you may need a regex.
On Sunday 10 December 2006 02:41, Steven Macintyre wrote:
> Hello,
>
> (a) I don't have php 5 :)
>
> (b) I have tried to use a < php 5 snippet from manual to no success ...
>
>
> I have a string like such ... "word another word
> yet another"
>
> Now ... from word to another word (excluding another word, including word)
> is 50 chars ... and the same fro another word to yet another ...
>
> I need to split this string and get those three "fields"
>
> I manage to get the first section right ...
>
> Example of string;
>
> $string = "EVOLUTION DEAR GOD
> BOYZ_II_MEN ";
>
> Will someone be able to assist me?
>
> I cannot strip spaces as some of the "words" will be double ... ie "Dear
> God" etc
>
>
> Kind Regards,
>
>
> Steven Macintyre
> http://steven.macintyre.name
> --
>
> http://www.friends4friends.co.za
--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson