我需要判断$_POSTphone是否以04开头,如果是,我想运行一个查询
在javascript中,我知道如何做到这一点,但由于某些原因,在Ubuntu 8(是的,我知道它很旧)和Firefox上,在反复测试我的javascript查询后,代理仍然能够在移动字段中发送04号码-我转而认为
发布于 2013-06-24 08:19:01
你可以像这样做一个子字符串:
if (substr($_POST['phone'], 0, 2) == '04') {
// ... do some code here
}如果你想同时匹配多个字符串,你可以这样做(它比in_array()更快):
$prefixes = array('02'=>true, '03'=>true, '07'=>true, '08'=>true);
$inputPrefix = substr($_POST['phone'], 0, 2);
if (isset($prefixes[$inputPrefix])) {
// ... do some code here
}发布于 2013-06-24 08:42:58
根据您的评论,如果您想确保它只有03、02、07或08,您可以执行以下操作:
$telephonePrefix = substr($_POST['phone'], 0, 2);
$knowPrefixes = array('03','02','07','08');
if (in_array($telephonePrefix , $knowPrefixes)) {
// ... do some code here
}https://stackoverflow.com/questions/17266503
复制相似问题