Jump to content

[SOLVED] Is there a command similar to "LIKE" within PHP?


Cless

Recommended Posts

Hello.

 

Is there any PHP command similar to the "LIKE" clause within SQL?

 

Typically, the LIKE clause finds out whether or not a piece of a string is located within a specified field in SQL. Basically, in SQL, you can do this:

 

<?PHP

//Find Rows
$result= mysql_query("SELECT * FROM users WHERE username LIKE '%pie%'");
$rows= mysql_fetch_array($result);

?>

 

That above would search for anybody with the word "pie" within their username.

 

Is there a way to do something similar to that with PHP? For example...

 

<?PHP

//Define Variables
$moo="blahmooblah";

//If Moo Is Found Within The Variable "Moo"
if($moo LIKE "%moo%")
{
}

?>

 

Obviously, that is not a practical scenario of what would occur.. Anyway, I know using "if($moo LIKE "%moo%")" will not work; which is what I am asking about.

 

Sorry if this is explained vaguely... I was not sure how to explain it.

 

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.