PHP if statement and LIKE?

Czukoman20
Czukoman20 used Ask the Experts™
on
I have information stored in a database as to what the user's category is.
An example would be $cat = ins_fp_IL

So I need to create an if statement that will return true if ins is in there (Similar to MySql LIKE statements)

Example of what I already have.
output needs to show
Category has the characters ins.

Thanks in advance!
<? php
$cat = "ins_FP_IL";
 
if ($cat == "ins") {
echo "Category has the characters ins";
}
else {
echo "Category doesn't have the characters ins";
}
?>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:

$cat = "ins_FP_IL";
 
if (false===strpos($cat, 'ins')) 
{
echo "Category doesn't have the characters ins";
}
else {
echo "Category has the characters ins";
}

Open in new window

Commented:
try
<? php
$cat = "ins_FP_IL";
$findCat = substr($cat, 1, 3); 
if ($findCat == "ins") {
echo "Category has the characters ins";
}
else {
echo "Category doesn't have the characters ins";
}
?>

Open in new window

Commented:
Or you could use regex:
$cat = "ins_FP_IL";
 
if (preg_match('/ins/is',$cat))
{echo "Category has the characters ins";
}
else {
echo "Category doesn't have the characters ins";
 
}

Open in new window

Commented:
sorry it should be
$findCat = substr($cat, 0, 3);

Author

Commented:
Very Awesome Worked PERFECTLY!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial