Page 1 of 1

checking a variable for a string

Posted: Sun Jan 04, 2004 11:34 am
by noaksey2000
alright people. all i want to do (if its possible) is to check if a string exists in a variable. for example i want to check, in an if statement, wherther the string '?h=' exists in the variable test.

Code: Select all

$test = "hello.php?h=ttt";

if (?h= is in $test)
echo "yes";
else
echo "no"
Is this possible?!
cheers, chris.

[Edit: Added PHP tags for eyecandy. --JAM]

Posted: Sun Jan 04, 2004 11:37 am
by JAM
Using [php_man]strstr[/php_man]().

Code: Select all

$test = "hello.php?h=ttt";
if (strstr($test,"?h=")) { // evals to TRUE
    echo "yes";
} else {
    echo "no";
}

Posted: Sun Jan 04, 2004 12:24 pm
by noaksey2000
nice one cheers mate