如何在php中使用switch case为动态页面标题匹配半个URL? [英] How to match half URL using switch case for dynamic page title in php?
本文介绍了如何在php中使用switch case为动态页面标题匹配半个URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在动态页面的开关案例中匹配URL。但我无法在开关案例中打印变量值。
I want to match URL in switch case for dynamic pages. But i am not able to print variable value in switch case.
这里是标题中我的html标题代码:
here is my html title code in header:
<title><?php echo $pageTitle; ?></title>
这是php:
$name=$_GET['id'];
switch ($_SERVER['PHP_SELF']){
case "/web/index.php":
$pageTitle = 'Home';
break;
case "/web/new_doc.php":
$pageTitle = 'Document';
break;
case "/web/new_provider.php":
$pageTitle = 'Provider';
break;
case "/web/read.php?id=$name":
$pageTitle = 'Reader';
break;
default:
$pageTitle ='Page';
我想匹配这样的网址:
read.php?id=amazon prime
book.php?id[]=A Wasted Hour&id[]=20
有没有什么方法可以匹配交换机案例中URL的一半,比如
read.php?id =而不是完整的URL。
is there any way that i can match half part of URL in switch case like read.php?id= instead of full URL.
推荐答案
标题HTML:
<head>
<title><?php echo $page_title; ?></title>
</head>
php code:
$page=$_SERVER['PHP_SELF'];
if($page=='/index.php')
{
$page_title = 'Home';
}elseif($page=='/read.php')
{
$name=$_GET['id'];
$page_title= 'Welcome '.$name;
}elseif($page=='/searchpag.php')
{
$page_title= 'Searchpage';
}
这篇关于如何在php中使用switch case为动态页面标题匹配半个URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文