我正在寻找一种根据网站URL显示一些代码的方法。
案例1:
如果网址包含getting-started
执行某些操作
案例2:
如果 url 包含getting-started/*
(可以是任何内容),则显示其他内容。
我目前得到的网址字符串为:
$url = $_SERVER['REQUEST_URI'];
然后执行strpos
if (strpos($slug,'getting-started')){
但是我需要一些东西来专门针对结尾getting-started
的URL,并且还能够识别何时有更多内容。
你应该使用正则表达式:
(getting-started)$ // gets the phrase at the end of the string
(getting-started)(.*) // gets the phrase + anything else
您可以将其与preg_match()
结合起来