我在数据库中有这样的值
123456789
826438758
?emailaddress1@test.com
?emailaddress2@test2.com
我正在动态地获取值,但我需要能够发现是否存在?值中。如果值中有一个问号,我想将它们重定向到其他地方
我认为我们可以用regex做到这一点,但不确定是如何
if (strpos($string, '?') === 0) {
//redirect
header("Location: http://www.example.com");
}
http://php.net/manual/en/function.strpos.php
===
很重要,因为当没有问号时,它将返回false
,并且false == 0
为true。
我只需要使用字符串索引
if ($string[0] === '?') {
echo 'header("Location: http://www.example.com");';
}
<?
if (preg_match('#^'?#', $str)) {
header('Location: http://google.com');
}