Web Hosting Talk







View Full Version : PHP Question on Conditions


phxhtml
11-23-2005, 06:47 PM
I have this code that looks for the URI and if it is true, then imserts an image.

<html>
<body>
YOU ARE LOOKING FOR:<BR><BR>

<?php
switch ($theuri = $_SERVER['REQUEST_URI']):

case ( ($theuri =="/") or ($theuri =="/city/Case_Studies/mario.php") );
echo $itemis = "<img src=\"images/arrow.gif\" alt=\"arrow \">
<span class=\"note\"> MARIO </span>";
break;

case ( ($theuri =="/") or ($theuri =="/city/Case_Studies/camila.php") );
echo $itemis = "<img src=\"images/arrow.gif\" alt=\"arrow \">
<span class=\"note\"> CAMILA </span>";
break;

case ( ($theuri =="/") or ($theuri =="/city/Case_Studies/jack.php") );
echo $itemis = "<img src=\"images/arrow.gif\" alt=\"arrow \">
<span class=\"note\"> JACK </span>";
break;

default:
echo "NOBODY IS HOME";
endswitch;
?>

</body>
</html>

IT works great, but the for the statement to be true the jack, camila and mario php files must be in the case statement

I want it to be true if the Case_Studies directory is found in the URI, not the enitre URI, so that I dont have to write case statements for every file in the DIR Case_Studies.

Thanks

Mark

Korvan
11-23-2005, 07:33 PM
I dont know what you mean by 'true' because you have 3 instances in the switch that I could consider true with different results. Also watch your syntax.

<?php
switch ($theuri = $_SERVER['REQUEST_URI'])
{
case "/city/Case_Studies/mario.php":
echo $itemis = "<img src=\"images/arrow.gif\" alt=\"arrow \"> <span class=\"note\"> MARIO </span>";
break;

case "/city/Case_Studies/camila.php":
echo $itemis = "<img src=\"images/arrow.gif\" alt=\"arrow \"> <span class=\"note\"> CAMILA </span>";
break;

case "/city/Case_Studies/jack.php":
echo $itemis = "<img src=\"images/arrow.gif\" alt=\"arrow \"> <span class=\"note\"> JACK </span>";
break;

default:
echo "NOBODY IS HOME";
}
?>


or are you looking for:


$theuri = $_SERVER['REQUEST_URI']
if(strpos($theuri, "Case_Studies"))
{
//true, "Case_Studies" is in the URI
}
else
{
//false "Case_studies" is not in the URI
}

Burhan
11-24-2005, 05:33 AM
I'm not exactly sure what you mean, but here is what I think you want to do.

If Case_Studies is in the URI, then take the file requested, remove the .php extension, capitalize the remaining filename, and output it in a span tag with an image:


if (strpos($_SERVER['REQUEST_URI'], "Case_Studies"))
{
echo '<img src="images/arrow.gif" alt="arrow"><span class="note">';
echo strtoupper(basename($_SERVER['REQUEST_URI'],'.php'));
echo '</span>';
} else {
echo 'No one here but us chickens! Bkwaaak Bkwaak!';
}

phxhtml
11-24-2005, 10:08 AM
Thank you for the replies.

fryster that looks like it would work for what i want to do. I want to have a unique image displayed based on the directory name (ie. Case_Studies) in the URI. Do you think it would accomplish this?

thanks