PHP question: text comparison in variable?

MDLarson

Registered
I'm just tweaking my PHP script now, and would like to detect whether a variable ($lodging_plan) includes the word "Delights". $lodging_plan is a radio button in this web form.

I'm trying to figure out if PHP has any text handling functions. Basically, if $lodging_plan includes the word "Delights", then do A, otherwise do B.

The code below uses the equals (=) sign. I'm sure double-equals (==) is not what I want, but I'm not sure what the difference is, and what else I should use...
Code:
if ( $lodging_plan = "Delights") {
     echo "This is a Doggy Delights plan" ;
     exit ;
} else {
     echo "This is not a Doggy Delights plan" ;
     exit ;
}
 
Hi,

If you make the If statement as follows:

if (strpos(" ".$lodging_plan,"Delights")) {

It will evaluate to true if $lodging_plan contains the word "Delights" anywhere within it. The space (" ") added at the start of $lodging_plan is to get over the problem of using strpos when the word you're looking for is at the start of the string.

Paul Perrins
www.netsourcesolutions.co.uk
 
Back
Top