RE: [PHP] Check if a word is in my string.

2001-08-28 Thread Jason Murray

> use:
> preg_match('/\Wgood\W/',$var);
> or
> preg_match('/\bgood\b/',$var);

Or, you could just try strstr($haystack, $needle) ...

Jason

-- 
Jason Murray
[EMAIL PROTECTED]
Web Developer, Melbourne IT
"Work now, freak later!"

-- 
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] Check if a word is in my string.

2001-08-28 Thread Papp Gyozo

Hi,

use:
preg_match('/\Wgood\W/',$var);
or
preg_match('/\bgood\b/',$var);

I don't know exactly.

- Original Message -
From: Brandon Orther <[EMAIL PROTECTED]>
To: PHP User Group <[EMAIL PROTECTED]>
Sent: Wednesday, August 29, 2001 12:02 AM
Subject: [PHP] Check if a word is in my string.


> Hello,
>
> I have a variable with a string in it.  I want to check if in that
> string a certain word is in it.  Example
>
> $var = "This is a good sentence";
>
> $check = look("good", $var);
>
>
> and $check would equal 1 since "good" is in that string
>
>
>
>
> does anyone know how to do this?
>



-- 
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] Check if a word is in my string.

2001-08-28 Thread scott [gts]

use regexps.  that's what their specialty is ;-)

// case insensitive
if ( preg_match("/$text/i", $string) ) {
print "$text is in $string";
}

// case sensitive
if ( preg_match("/$text/", $string) ) {
print "$text is in $string";
}

> -Original Message-
> From: daniel james [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 28, 2001 6:11 PM
> To: Brandon Orther; PHP User Group
> Subject: Re: [PHP] Check if a word is in my string.
> 
> 
> if you're just looking for the 1st occurrence of the
> string, it's--
> 
> $check = "good";
> $var = "This is a good...";
> 
> if (!strstr($var, $check)) {
> print("$check not found");
> }
> 
> also, i think strstr() is case-insensitive, so it
> won't be able to differentiate between 'Good' and
> 'good', and will NOT return FALSE if 'Good' precedes
> 'good' in the string...
> 
> -dj
> 
> 
> --- Brandon Orther <[EMAIL PROTECTED]> wrote:
> > Hello,
> >  
> > I have a variable with a string in it.  I want to
> > check if in that
> > string a certain word is in it.  Example
> >  
> > $var = "This is a good sentence";
> >  
> > $check = look("good", $var);
> >  
> >  
> > and $check would equal 1 since "good" is in that
> > string
> >  
> >  
> >  
> >  
> > does anyone know how to do this?
> > 
> 
> 
> __
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/
> 
> -- 
> 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] Check if a word is in my string.

2001-08-28 Thread daniel james

if you're just looking for the 1st occurrence of the
string, it's--

$check = "good";
$var = "This is a good...";

if (!strstr($var, $check)) {
print("$check not found");
}

also, i think strstr() is case-insensitive, so it
won't be able to differentiate between 'Good' and
'good', and will NOT return FALSE if 'Good' precedes
'good' in the string...

-dj


--- Brandon Orther <[EMAIL PROTECTED]> wrote:
> Hello,
>  
> I have a variable with a string in it.  I want to
> check if in that
> string a certain word is in it.  Example
>  
> $var = "This is a good sentence";
>  
> $check = look("good", $var);
>  
>  
> and $check would equal 1 since "good" is in that
> string
>  
>  
>  
>  
> does anyone know how to do this?
> 


__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

-- 
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] Check if a word is in my string.

2001-08-28 Thread Philip Olson

see :

  http://www.php.net/strstr
  http://www.php.net/stristr

Regards,
Philip


On Tue, 28 Aug 2001, Brandon Orther wrote:

> Hello,
>  
> I have a variable with a string in it.  I want to check if in that
> string a certain word is in it.  Example
>  
> $var = "This is a good sentence";
>  
> $check = look("good", $var);
>  
>  
> and $check would equal 1 since "good" is in that string
>  
>  
>  
>  
> does anyone know how to do this?
> 


-- 
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]