Re: Splitting string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx		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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux