Php 如何使用strpos()代替preg_match())

Php 如何使用strpos()代替preg_match()),php,Php,我有一个脚本,当冲浪者来自某些网站时,它包含文件,它看起来像这样: <?php $referral = $_SERVER['HTTP_REFERER']; if (preg_match('/yahoo.com\/main.html|yahoo.com\/secound.html/', $referral)) { require_once ('a.php'); } else if (preg_match('/google.com/', $referral)) { require_once (

我有一个脚本,当冲浪者来自某些网站时,它包含文件,它看起来像这样:

<?php
$referral = $_SERVER['HTTP_REFERER'];
if (preg_match('/yahoo.com\/main.html|yahoo.com\/secound.html/', $referral)) {
require_once ('a.php');
} else if (preg_match('/google.com/', $referral)) {
require_once ('b.php');
} else {
require_once ('c.php');
}
?>

但它正在杀死我的服务器,我想用strops()替换它,但我不知道怎么做,我尝试了以下方法:

<?php
$referral = $_SERVER['HTTP_REFERER'];
if (strops('/yahoo.com\/main.html|yahoo.com\/secound.html/', $referral)) {
require_once ('a.php');
} else if (strops('/google.com/', $referral)) {
require_once ('b.php');
} else {
require_once ('c.php');
}
?>


但它不起作用:(

请看这里的PHP文档:

Strpos在另一个字符串中找到一个特定的字符串,因此您不能使用正则表达式。您可以只找到一个特定的字符串

e、 g

strpos('google.com',$reference')


对于包含
google.com
的任何字符串,都将返回
true
。如果您想检测多个不同的字符串,可以将多个strpo组合在一起(使用or运算符),或者坚持使用当前的方法。

请查看以下PHP文档:

<?php
$referral = $_SERVER['HTTP_REFERER'];
if ((strpos($referral, 'yahoo.com/main.html')!==false)
  ||(strpos($referral, 'yahoo.com/secound.html')!==false)) {
require_once ('a.php');
} else if (strpos($referral, 'google.com')!==false) {
require_once ('b.php');
} else {
require_once ('c.php');
}
?>
Strpos在另一个字符串中找到一个特定的字符串,因此您不能使用正则表达式。您可以只找到一个特定的字符串

e、 g

strpos('google.com',$reference')

对于包含
google.com
的任何字符串,都将返回
true
。如果您想检测多个不同的字符串,可以将多个strpo组合在一起(使用or运算符),或者坚持使用当前方法。


<?php
$referral = $_SERVER['HTTP_REFERER'];
if ((strpos($referral, 'yahoo.com/main.html')!==false)
  ||(strpos($referral, 'yahoo.com/secound.html')!==false)) {
require_once ('a.php');
} else if (strpos($referral, 'google.com')!==false) {
require_once ('b.php');
} else {
require_once ('c.php');
}
?>


strops这是什么?strops()不使用regex这是什么?strops()不使用regexThanks。我可以像strops('google.com\/main.html',$reference')或strops('google.com\/main.html | yahoo.com\/two.html',$reference')这样做吗?如果(strpos('google.com',$refereal')或strpos('yahoo.com',$refereal')){/code>,等等。但它不是特别整洁。谢谢。我可以做一些类似strpos('google.com\/main.html',$refereal')或strpos('google.com\/main.html | yahoo.com\/two.html',$refereal')的事情吗?你可以这样做:
如果(strpos('google.com',$refereal')或strpos)('yahoo.com',$refereal'){
等。但它不是特别整洁。使用stripos也可能不是个坏主意。它是大小写独立的,谁知道你会在referer头中看到哪种情况…使用stripos也可能不是个坏主意。它是大小写独立的,谁知道你会在referer头中看到哪种情况。。。