Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does a "Like" Command Exist??

Status
Not open for further replies.
May 22, 2002
63
GB
Hi,

Is there such a think as the 'like' command in PHP that can be used as:

if ($value like "hello"){
print "whatever";
}

As you can in MySQL??

Thanks,

Anders
 
If I recall in mySQL, "Like" merely means "if the string you're searching in contains the string you're searching for". So, you could use substr. The following code:

substr("test", "1 2 test 3 4 test")

would return "test 3 4 test". Basically, everything from the first ocurrance of 'test' to the end of the string. But that doesn't matter. As long as the substr function evalutes to something other than FALSE, then you know you found what you were looking for.

I use it all the time like this:

if (substr($looking_for, $looking_in));
{
(do whatever)
}

As long as what I'm $looking_for is found in what I'm $lookin_ing, the block will be executed.
 
disord3r,

The function you are talking about is strstr, substr gets a part of a string, specified by two integers. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top