Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用preg_match查找URL中的单词(或不带空格的字符串)_Php_Regex_Preg Match - Fatal编程技术网

Php 使用preg_match查找URL中的单词(或不带空格的字符串)

Php 使用preg_match查找URL中的单词(或不带空格的字符串),php,regex,preg-match,Php,Regex,Preg Match,对不起,我对regex有点陌生,不管怎样,我有一个像http://example.com/test/folder/?get=ThisisaValue 我需要它来返回get这个词是否在那里 每当我运行函数时,都没有匹配项?谢谢你的帮助 示例代码,假设$\u服务器['HTTP\u REFERER']是http://example.com/hello/?state=12345 我需要它来返回get这个词是否在那里 在这种情况下,您不需要匹配任何内容,只需使用strpos检查子字符串是否在字符串中 我需

对不起,我对regex有点陌生,不管怎样,我有一个像http://example.com/test/folder/?get=ThisisaValue 我需要它来返回get这个词是否在那里

每当我运行函数时,都没有匹配项?谢谢你的帮助

示例代码,假设$\u服务器['HTTP\u REFERER']是http://example.com/hello/?state=12345

我需要它来返回get这个词是否在那里

在这种情况下,您不需要匹配任何内容,只需使用strpos检查子字符串是否在字符串中

我需要它来返回get这个词是否在那里

在这种情况下,您不需要匹配任何内容,只需使用strpos检查子字符串是否在字符串中


您忘记了分隔符:

preg_match("~state~", $_SERVER['HTTP_REFERER'])

现在它应该可以工作了:

您忘记了分隔符:

preg_match("~state~", $_SERVER['HTTP_REFERER'])

现在它应该可以工作了:

对不起,我只是指函数preg\u match。基本上我的代码是:preg_matchget,http://example.com/test/folder/?get=ThisisaValuesorry 我只是指功能预匹配。基本上我的代码是:preg_matchget,http://example.com/test/folder/?get=ThisisaValuePerfect,这正是我要找的。谢谢完美,这正是我想要的。非常感谢。
preg_match("~state~", $_SERVER['HTTP_REFERER'])