Php 基于url的If语句包含

Php 基于url的If语句包含,php,regex,Php,Regex,我知道这对于那些遵循php标签的人来说是非常基本的,但我是一个学习开发第一个插件的人 我根据访问者正在查看的页面生成元标记 使用php,我该怎么说 IF url contains "^/reports/view/*" then do this(), Else do that() 我不是在问IF语句的语法,我能理解。它在php中使用正则表达式。我试图针对的特定页面集从/reports/view/开始,然后是后面的内容 以下是我希望针对的一些示例页面: example.com/reports/vi

我知道这对于那些遵循php标签的人来说是非常基本的,但我是一个学习开发第一个插件的人

我根据访问者正在查看的页面生成元标记

使用php,我该怎么说

IF url contains "^/reports/view/*" then do this(),
Else do that()
我不是在问IF语句的语法,我能理解。它在php中使用正则表达式。我试图针对的特定页面集从
/reports/view/
开始,然后是后面的内容

以下是我希望针对的一些示例页面:

example.com/reports/view/somepage.php
example.com/reports/view/someotherpage.php

我以前使用过
if==
,但从未使用过这种意义上的contains。

在这种情况下似乎没有必要使用正则表达式:您可以很好地使用方法:

if (strpos('/reports/view/', $url) === 0) {
  // $url begins with '/reports/view/'
}

if (strpos('/reports/view/', $url) !== FALSE) {
  // $url contains '/reports/view/' substring
}

这是不同的支票,示例补充道。谢谢。也谢谢其他人检查这个答案,因为他们先到了。