View Full Version : find a?

11-05-2010, 03:18 PM
Hey, What function / how would I find if a string has something? Say I have a string like:

$string = 'Hello their! This is my post :) btw, my name is Justin.';

Say I wanted to find out if my name "Justin" is inside that string..

whateverfunction('Justin', $string)

So I think you should get my idea now though :P

Thanks a lot!

11-05-2010, 03:25 PM
have a look at preg_match()


11-05-2010, 03:25 PM
One way of doing it is the following:

if (strpos($string, 'Justin') !== false)
return true;

This is case sensitive (use stripos for case insensitive), but will also return true if the string contains "ffafafdjustinDSd". preg_replace can be used if you want to prevent this latter example from returning true (as mentioned in the previous post).

11-05-2010, 03:26 PM
preg_match() (http://ru.php.net/manual/en/function.preg-match.php)

11-05-2010, 03:30 PM
strpos() is the superior option in this case.

There is also stripos() that will perform a case-insensitive match.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum