Re: split on whitespace, preserving whitespace...
| From: | Alexandr Grinko | Date: | Fri, 20 Jul 2001 19:19:31 +0000 |
| Subject: | Re: split on whitespace, preserving whitespace... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-58969@lists.php.net to get a copy of this message | ||
http://www.zend.com/zend/spotlight/spellchecking.php
----- Original Message -----
From: "Don Read" <dread@texas.net>
To: "Garth Dahlstrom" <garth@utmail.to>
Cc: <php-general@lists.php.net>
Sent: Friday, July 20, 2001 11:41 PM
Subject: RE: [PHP] split on whitespace, preserving whitespace...
>
> On 20-Jul-2001 Garth Dahlstrom wrote:
> > Hi all,
> >
> > I'm trying to build a spell checker for a web form.
> > What has got me stumped is being able to do a split
> > so that whitespace and words are stored as seperate
> > elements of the same array.
> >
> > ideally, I'd use some form of preg_split to put:
> >
> > "This contans white space ."
> >
> > into an array like:
> >
> > $wordsarr = ('This',' ','contans','
> > ','white',' ','space',' ','.')
> >
> > So that I can do a a loop as follows:
> >
> > for ($i = 0; $i < count($wordarr); $i++)
> > {
> > if (!trim($wordarr[$i]) == "" &&
> > !eregi(trim($wordarr[$i]),'.,/'))
> > {
> > file://check spelling
> > file://correct errors
> > }
> > echo $wordarr[$i];
> > }
> > and end up with:
> > "This contains white space ."
> >
> > can a split like this be accomplished using
> > preg_split or do I need to go through the string
> > one space at a time in a while loop?
> >
> > -Garth
>
> start with preg_split(/^\w+/, $foo);
>
> (read as: split on one or more non-word charachers)
>
>
> Regards,
> --
> Don Read dread@texas.net
> -- It's always darkest before the dawn. So if you are going to
> steal the neighbor's newspaper, that's the time to do it.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>