checking a variable for a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
noaksey2000
Forum Newbie
Posts: 5
Joined: Sun Aug 17, 2003 10:29 am

checking a variable for a string

Post 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]
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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";
}
noaksey2000
Forum Newbie
Posts: 5
Joined: Sun Aug 17, 2003 10:29 am

Post by noaksey2000 »

nice one cheers mate
Post Reply