Re: [PHP] split on whitespace, preserving whitespace...

2001-07-20 Thread Garth Dahlstrom

Yup, I hear that... I'm going to use something like the following to 
do my pspell application...


[$text][". implode('|',$matches)."]";
?>



On Fri, 20 Jul 2001 15:11:26 -0500 "Brad S. Jackson" wrote:

> 
> 
> I got this to work.  I wish I had found this when I wrote our pspell
> code.  I
> wrote code that loops through each character to get the words and
> preserve white
> space.  I also wrote a whole bunch of code that strips punctuation
> from the
> beginning and end of words and has regex checking for numbers, dates
> and times.
> 
> $text = "This is a lotta
> text.  How do you like that?";
> 
> preg_match_all("/(\\S+)|(\\s+)/ms", $text, $array);
> 
> echo "";
> print_r($array[1]);
> 
> 
> Garth Dahlstrom <[EMAIL PROTECTED]> 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  contanswhite 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]),'.,/'))
>   {
>  //check spelling
>  //correct errors
>   }
>   echo $wordarr[$i];
> }
> and end up with:
> "This  containswhite 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
> 
> Northern.CA ===---
> http://www.northern.ca
> 
> 



Northern.CA ===--
http://www.northern.ca 
Canada's Search Engine



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] split on whitespace, preserving whitespace...

2001-07-20 Thread Alexandr Grinko

http://www.zend.com/zend/spotlight/spellchecking.php


- Original Message -
From: "Don Read" <[EMAIL PROTECTED]>
To: "Garth Dahlstrom" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
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  contanswhite 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  containswhite 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   [EMAIL PROTECTED]
> -- 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] split on whitespace, preserving whitespace...

2001-07-20 Thread Don Read


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  contanswhite 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]),'.,/'))
>   {
>  //check spelling
>  //correct errors
>   }
>   echo $wordarr[$i];
> }
> and end up with:
> "This  containswhite 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   [EMAIL PROTECTED]
-- 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] split on whitespace, preserving whitespace...

2001-07-20 Thread Don Read


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  contanswhite 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]),'.,/'))
>   {
>  //check spelling
>  //correct errors
>   }
>   echo $wordarr[$i];
> }
> and end up with:
> "This  containswhite 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
> 

$line='Just a test; (some) text for checking stuff/things.';
$words=preg_split("/[^\w]+/", $line);

echo $line, '';
while (list ($k, $v) = each($words)) {
echo "$k -> $v", '';
}

Regards,
-- 
Don Read   [EMAIL PROTECTED]
-- 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] split on whitespace, preserving whitespace...

2001-07-19 Thread Garth Dahlstrom

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  contanswhite 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]),'.,/'))
  {
 //check spelling
 //correct errors
  }
  echo $wordarr[$i];
}
and end up with:
"This  containswhite 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

Northern.CA ===---
http://www.northern.ca



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]