Date: 11/15/00
- Next message: Cheng-Wei Cheng: "[PHP] RE: Tomcat 3.2 beta and PHP"
- Previous message: Michael Kimsal: "Re: [PHP] [PHP + PDFLib] PHP "streaming" of PDF files"
- In reply to: Paul Tuohy: "[PHP] counting matches with eregi()"
- Next in thread: Robert V. Zwink: "RE: [PHP] counting matches with eregi()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, 15 Nov 2000, Paul Tuohy wrote:
> I want to count the number of times a word appears in a string. I am using
> php3/linux
>
> Say I have a string:
>
> $string = "my house is a new house but not a big house in my household"
>
> I want to count how many times the word 'house' appears. If I use
> parentheses and include a $matches array in an eregi function, it stores
> partial matches, not a count of full matches in the entire string.
>
> Also the manual says that word boundary \b should work with php3, but the
> series of statments:
>
> $pattern = "\bhouse\b"
> $test = eregi($pattern, $string, $matches);
>
> return with no matches. I need to make sure that 'household' is not included
> in the count of whole words. what am i doing wrong?
>
No, \b works with preg*(), not ereg*(). You probably want something like
"[^[:alnum:]]house[^[:alnum:]]".
-- Ignacio Vazquez-Abrams <ignacio <email protected>>-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Cheng-Wei Cheng: "[PHP] RE: Tomcat 3.2 beta and PHP"
- Previous message: Michael Kimsal: "Re: [PHP] [PHP + PDFLib] PHP "streaming" of PDF files"
- In reply to: Paul Tuohy: "[PHP] counting matches with eregi()"
- Next in thread: Robert V. Zwink: "RE: [PHP] counting matches with eregi()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

