Link to home
Start Free TrialLog in
Avatar of pixelscape
pixelscape

asked on

Comparing part of a variable value

I have a session whose value is either something like this rose_portraitlg.jpg or this rose_landslg.jpg. The only thing that is constant in these file names is the portrait or lands. I need to be able to compare variable in an if statement to determine if portrait or lands is in the variable named.

$virtualcomp = $_SESSION['virtualimage'];
...

if ( $virtualcomp == portrait) {
echo "<img src='awards/".$_SESSION['virtualimage']."' width='445' height='607'/>";
}

else {
echo "<img src='awards/".$_SESSION['virtualimage']."' width='560' height='430'/>";
}
ASKER CERTIFIED SOLUTION
Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if (strpos($virtualcomp, 'portrait') !== false) {
echo "<img src='awards/".$_SESSION['virtualimage']."' width='445' height='607'/>";
} else {
echo "<img src='awards/".$_SESSION['virtualimage']."' width='560' height='430'/>";
}

Open in new window

Avatar of teedo757
teedo757

In case you were wondering why if (strpos($virtualcomp, 'portrait') !== false) works

The strpos() function returns the position of the first occurrence of a string inside another string.

If the string is not found, this function returns FALSE.
Avatar of pixelscape

ASKER

Gotcha, thanks for the input guys.