As longs as none of the text you are using NEEDS spaces you can just do
this:

<?php

$string ="text1, te xt2, t e x t 3";
$string = ereg_replace(" ", "", $string);
$array = explode(",", $string);
echo "|" . $array[0] . "|" . $array[1] . "|" . $array[2] . "|";

?>

If you want to keep the spaces and there is always a space after the
comma you can do:

$string = ereg_replace(", ", ",", $string);

Instead of the other ereg_replace above.

Brian 

> -----Original Message-----
> From: Kris [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, January 21, 2003 6:29 PM
> To: Brian T. Allen; 'Jason k Larson'
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP] Re: fscanf
> 
> 
> Actually found a little problem
> 
> I forgot to mention some lines can be
> 
> text, t e x t, te xt
> t e xt, text, text
> 
> This splits it into more then 3 parts.
> Any ideas on this? Shouldn't I be able to use just fscanf to 
> get the results
> I'm after??
> 
> Thanks
> 
> K
> 
> ----- Original Message -----
> From: "Brian T. Allen" <[EMAIL PROTECTED]>
> To: "'Kris'" <[EMAIL PROTECTED]>; "'Jason k Larson'"
> <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Wednesday, January 22, 2003 10:58 AM
> Subject: RE: [PHP] Re: fscanf
> 
> 
> > Given the information below this works:
> >
> > <?php
> >
> > $string ="text1, text2, text3";
> > $array = preg_split("/[, ]/", $string, -1, PREG_SPLIT_NO_EMPTY);
> > echo "|" . $array[0] . "|" . $array[1] . "|" . $array[2] . "|";
> >
> > ?>
> >
> > I put it between pipes to confirm the absence of spaces...
> >
> > It may or may not be the best way, but it is one way.
> >
> > Brian
> >
> > > -----Original Message-----
> > > From: Kris [mailto:[EMAIL PROTECTED]]
> > > Sent: Tuesday, January 21, 2003 5:02 PM
> > > To: Jason k Larson
> > > Cc: [EMAIL PROTECTED]
> > > Subject: Re: [PHP] Re: fscanf
> > >
> > >
> > > I've tried
> > > $array = fscanf ($fp, "%s, %s, %s\n");
> > > earlier. It picks up
> > > array[0] == text,
> > >
> > > I need
> > > array[0] == text
> > > array[1] == text
> > > array[2] == text
> > >
> > > Thanx
> > >
> > > K
> > >
> > > ----- Original Message -----
> > > From: "Jason k Larson" <[EMAIL PROTECTED]>
> > > To: "Kris" <[EMAIL PROTECTED]>
> > > Cc: <[EMAIL PROTECTED]>
> > > Sent: Wednesday, January 22, 2003 9:52 AM
> > > Subject: Re: [PHP] Re: fscanf
> > >
> > >
> > > > I think he is looking more for:
> > > > $array = fscanf ($fp, "%s, %s, %s\n");
> > > >
> > > > But with split, wouldn't that need to be:
> > > >
> > > > $array = split(', ', $line);
> > > >
> > > > http://www.php.net/manual/en/function.split.php
> > > > or
> > > >
> > > > $array = preg_split ('/[\s,]+/', $line);
> > > > using: http://www.php.net/manual/en/function.preg-split.php
> > > >
> > > > HTH,
> > > > Jason k Larson
> > > >
> > > >
> > > > Philip Hallstrom wrote:
> > > > > Why not:
> > > > >
> > > > > $array = split("[ ,]", $line);
> > > > >
> > > > > ?
> > > > >
> > > > > On Wed, 22 Jan 2003, Kris wrote:
> > > > >
> > > > >
> > > > >>Hi
> > > > >>
> > > > >>I'm having dramers with fscanf
> > > > >>I have a line:
> > > > >>text, text, text
> > > > >>
> > > > >>I can't work out how to scan removing the comma and 
> whitespace.
> > > > >>the text can be absolutle anything.
> > > > >>
> > > > >>at the moment I have
> > > > >>$array = fscanf ($fp, %s%[^,] %s%[^,] %s%[^,]);
> > > > >>
> > > > >>Thanks
> > > > >>
> > > > >>Kris
> > > >
> > > >
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > >
> > > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> > >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
> 


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

Reply via email to