Re: [PHP] vertical word match SOLUTION From: 'Joe Rice' (riceja <email protected>)
Date: 07/19/02

I can't take full credit for this. i asked a fellow perl
programmer and he muttered the words, "why bother
searching for newlines and spaces". so, now searching
for any layout of the word will work.

$answer = "hello\na\np\np\nl\ne\n"; /*from textarea in form*/
/* replace all whitespace and newlines with nothing */
$tempanswer = preg_replace("/\s*|\n*/","",$answer);
$word = "apple";
/* match on the new condensed answer */
preg_match("/".$word."/i",$tempanswer,$match)

and this works for "red apple" as well.

thanks,
joe

'Joe Rice'(riceja <email protected>) <email protected>, Jul 19, 2002 at 10:09:55AM -0500:
>
> i though i had tried this. but, i just did again and it
> still isn't matching. I've read that browsers send
> different things for the newline from <textarea> but, i've
> tried
> Netscape,IE on windows
> Netscape, Mozilla on Solaris
>
> I really think what i have should work.
> $word gets set to
>
> (.?|\s*|\n*|)r(.?|\s*|\n*|)(.?|\s*|\n*|)e(.?|\s*|\n*|)(.?|\s*|\n*|)d(.?|\s*|\n*|)(.?|\s*|\n*|) (.?|\s*|\n*|)(.?|\s*|\n*|)a(.?|\s*|\n*|)(.?|\s*|\n*|)p(.?|\s*|\n*|)(.?|\s*|\n*|)p(.?|\s*|\n*|)(.?|\s*|\n*|)l(.?|\s*|\n*|)(.?|\s*|\n*|)e(.?|\s*|\n*|)
>
>
> (match 0 or 1 of anything | match 0 or more of any white space | match 0 or more of newline)
> r
> (match 0 or 1 of anything | match 0 or more of any white space | match 0 or more of newline)
> e
> (match 0 or 1 of anything | match 0 or more of any white space | match 0 or more of newline)
> d
> (match 0 or 1 of anything | match 0 or more of any white space | match 0 or more of newline)
>
> (match 0 or 1 of anything | match 0 or more of any white space | match 0 or more of newline)
> a
>
>
> and so on...
> the only thing i can think of is the "space" between the words that
> i'm not matching.
>
> if anyone can help, i would appreciate it.
> thanks,
> joe
>
>
> Martin Towell(martin.towell <email protected>) <email protected>, Jul 19, 2002 at 04:06:03PM +1000:
> > try changing the "+"'s with "*"'s
> > + = 1 or more
> > * = 0 or more
> >
> > -----Original Message-----
> > From: Joe Rice [mailto:riceja <email protected>]
> > Sent: Friday, July 19, 2002 3:30 PM
> > To: php-general <email protected>
> > Subject: [PHP] vertical word match
> >
> >
> >
> > hello,
> > any regex gurus?
> > i'm trying to match words put into a <textarea>
> > that are in the form of a\np\np\l\e
> > or any combination of new lines in between, before
> > or after.
> >
> > $answer = "hello\na\np\np\nl\ne\n"; /*from textarea in form*/
> > $word = "apple";
> > $word = preg_replace("/(.)/","(.?|\s+|\n+|)$1(.?|\s+|\n+|)",$word);
> > preg_match("/".$word."/im",$answer,$match)
> >
> > works.
> > but if
> >
> > $word = "red apple";
> > $answer = "r\ne\nd\n\na\np\np\nl\e";
> >
> > it doesn't match.
> >
> >
> > thanks in advance,
> > joe
> >
> > --
> > 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
> >
>
> --
> How do i get rid of those words in my screen that are coming from you?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-- 
How do i get rid of those words in my screen that are coming from you?

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