Reputation: 294
Is it possible to create a PHP switch, which checks a URL's for a specific string? I'm using $_GET to customize the URL'S of specific pages depending on various situations. I want to trim down the Url and check it against several cases. Here is the code I have so far.
Here is the an example of the URL:
www.example.com/page/resource/view.php?id=417&module=1&menuid=4&module=1&page=4
<?php
// Grabs the page URL
$url = curPageURL();
var_dump($url);
$trimURL = trim($url);
var_dump($trimmed);
$trimmed = trim($text, "resource/view.php?id=417&module=1& || &module=1&page=4");
var_dump($trimmed);
// The Switch
switch ($trimmed) {
case "menuid=1":
echo "Menu ID 1";
break;
case "menuid=2":
echo "Menu ID 2";
break;
case "menuid=2":
echo "Menu ID 3";
break;
default:
echo "No Menu Number Detected.";
}
?>
Upvotes: 1
Views: 637
Reputation: 21830
switch($_GET["menuid"]) {
case "1":
echo "Menu ID 1";
break;
case "2":
echo "Menu ID 2";
break;
}
Upvotes: 3