Re: Splitting string
| From: | Larry Garfield | Date: | Sun, 10 Dec 2006 16:39:25 +0000 |
| Subject: | Re: Splitting string | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-245689@lists.php.net to get a copy of this message | ||
On Sunday 10 December 2006 04:57, Steven Macintyre wrote:
> > $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.
>
> Tried this ... and it returns $arr[0] as EVOLUTION DEAR GOD BOYZ_II_MEN ...
> which in fact is wrong ... I would like ...;
>
> $arr[0] => EVOLUTION "word + spaces = 50 chars"
> $arr[1] => DEAR GOD "words + spaces = 50 chars"
>
> Etc ...
>
> Steven
Ah, so it's not 50 space padding but columns at 50 characters, space-padded?
In that case, just use substr().
$var1 = substr($string, 0, 50);
$var2 = substr($string, 50, 50);
$var3 = substr($string, 100, 50);
And then trim() if needed
Of course, what it sounds like you really want is a file that is formatted to
proper CSV in the first place so that you can use fgetcsv().
--
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