6

我不知道这是否足以提供数据,但我有

preg_match('/SAMPLETEXT/', $bcurl, $cookie1);

我想知道我能不能做到

preg_match($newfunction, $bcurl, $cookie1);

但是当我这样做时,我收到此错误“警告:preg_match() [function.preg-match]:分隔符不能是字母数字或反斜杠”。

我怎样才能让它检查我的新功能,而不是让它只检查“SAMPLETEXT”。

4

3 回答 3

15

尝试preg_match("/$newfunction/", $bcurl, $cookie1);提供所需的分隔符(使用不会出现在 $newfunction 中的分隔符)。

但请注意,文档中说“如果您只想检查一个字符串是否包含在另一个字符串中,请不要使用 preg_match()。请改用 strpos() 或 strstr(),因为它们会更快。”

于 2009-09-06T21:22:29.663 回答
7

preg_match('/'.$pattern.'/i', $subject)

i选项:允许大写字母或连字符。

于 2015-06-12T16:26:48.303 回答
-3

您可以通过将变量放在 [] 之间来使用变量

    $subject = "abcdef";
$ch = 'b';
$pattern = '/[$ch]/';
preg_match($pattern, $subject, $matches);
//print_r($matches);
if ($matches)
{
    echo $subject;
}
于 2012-11-13T13:23:03.997 回答