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['v irtualimag e']."' width='445' height='607'/>";
}
else {
echo "<img src='awards/".$_SESSION['v irtualimag e']."' width='560' height='430'/>";
}
$virtualcomp = $_SESSION['virtualimage'];
...
if ( $virtualcomp == portrait) {
echo "<img src='awards/".$_SESSION['v
}
else {
echo "<img src='awards/".$_SESSION['v
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
Gotcha, thanks for the input guys.
Open in new window