数组里的前几个数字怎么判断。并给出分值 数组里的前几个数字怎么判断。并给出分值如果数组是以800 开头的。。给这个数组500分80开头的。。 给这个数组50分400 开头的。。给这个数组500分40 开头的。。给这个数组50分 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $str="80080000";$newstr=$str[0].$str[1].$str[2];不过,最好用substr来判断。也可以用strpos,先判断长的,比如800,再判断短的,80.另外,你的规则设定有问题,80包含了800。 $str=要检查的数字串;if(preg_match('/^[8][0][0].$/',$str)){ 以800开头:给500分;}if(preg_match('/^[8][0][^0].$/',$str)){ 以80开头:给50分;} $str="80080000";echo preg_replace('/(80+).+/', '$1', $str); //800echo preg_replace('/(80+).+/e', 'strlen("$1")', $str); //3$str="801234";echo preg_replace('/(80+).+/', '$1', $str); //80echo preg_replace('/(80+).+/e', 'strlen("$1")', $str); //2利用 preg_replace('/(80+).+/e', 'strlen("$1")', $str); 的结果,查询分值表即可 果断使用strpos函数,什么正则丢一边 出错阿~<?php $str='80123';if(preg_match('/^[8][0][0].$/',$str)){ echo 500;}if(preg_match('/^[8][0][^0].$/',$str)){ echo 50;?> 用 substr 或 perg_match都可以实现 <?php $str='800123';if(ereg("^[8][0][0].",$str))//POSIX 风格{ echo '500';}if(preg_match('/^[8][0][^0]./',$str))//PCRE风格{ echo '50';}?>以上可以运行。 你说strpos 查找80的时候 800 会怎么样呢? 其实你嫌弃麻烦的话还可以$str = '8001606';if ($str{0} === '8') { } magento 商品显示问题 php怎么写这段js的代码? php socket 发邮件 显示表中的内容 不知道字段的情况下 关于php_memcache.dll 扩展安装的问题。。 新手求指点 php有抓取动态数据的组件不 请教cms问题 提个最简单的问题,散点分!!! apache 禁止访问外部链接 超大的sql文件怎么导入本地数据库啊?大概25G,求大神指点下!!! 网站服务器疑似被攻击出现"Welcome to nginx!"? PHP求一等式,由于本人比较菜。
$newstr=$str[0].$str[1].$str[2];
不过,最好用substr来判断。也可以用strpos,先判断长的,比如800,再判断短的,80.
另外,你的规则设定有问题,80包含了800。
if(preg_match('/^[8][0][0].$/',$str))
{
以800开头:给500分;
}
if(preg_match('/^[8][0][^0].$/',$str))
{
以80开头:给50分;
}
echo preg_replace('/(80+).+/', '$1', $str); //800
echo preg_replace('/(80+).+/e', 'strlen("$1")', $str); //3$str="801234";
echo preg_replace('/(80+).+/', '$1', $str); //80
echo preg_replace('/(80+).+/e', 'strlen("$1")', $str); //2利用 preg_replace('/(80+).+/e', 'strlen("$1")', $str); 的结果,查询分值表即可
$str='80123';
if(preg_match('/^[8][0][0].$/',$str))
{
echo 500;
}
if(preg_match('/^[8][0][^0].$/',$str))
{
echo 50;
?>
$str='800123';
if(ereg("^[8][0][0].",$str))//POSIX 风格
{
echo '500';
}
if(preg_match('/^[8][0][^0]./',$str))//PCRE风格
{
echo '50';
}
?>
以上可以运行。
你说strpos 查找80的时候 800 会怎么样呢?
}