Home > Backend Development > PHP Tutorial > CodeIgniter PHP 显示值截取-值

CodeIgniter PHP 显示值截取-值

WBOY
Release: 2016-06-23 14:38:49
Original
1057 people have browsed it




-----------------------
上面显示的值:057188885281-001
怎么截取-后面001 

大虾求解


回复讨论(解决方案)

$str='057188885281-001';$str=$value['haoma'];echo substr($str,stripos($str,'-')+1);
Copy after login
Copy after login
Copy after login
Copy after login

$str='057188885281-001';$str=$value['haoma'];echo substr($str,stripos($str,'-')+1);
Copy after login
Copy after login
Copy after login
Copy after login

现在是可以截取到了,但是如果有些号码没有-001 可以为空不?
----------------------
显示:
号码 工号
057188885281-001 001
057188885282


$str='057188885281-001';$str=$value['haoma'];echo substr($str,stripos($str,'-')+1);
Copy after login
Copy after login
Copy after login
Copy after login

现在是可以截取到了,但是如果有些号码没有-001 可以为空不?
----------------------
显示:
号码 工号
057188885281-001 001
057188885282

为空可以啊,有啥问题?自己试下代码不就好了



$str='057188885281-001';$str=$value['haoma'];echo substr($str,stripos($str,'-')+1);
Copy after login
Copy after login
Copy after login
Copy after login

现在是可以截取到了,但是如果有些号码没有-001 可以为空不?
----------------------
显示:
号码 工号
057188885281-001 001
057188885282

为空可以啊,有啥问题?自己试下代码不就好了

foreach ( $info as $key => $value)
{

}

--------------------
在循环显示出来的时候,有的是没有带工号的
--------------------------
现在的效果是:
号码 工号
057188885281-001 001
057188885282 057188885282

--------------------------
我想要的效果是:
号码 工号
057188885281-001 001
057188885282

$str = '057188885281-001';$str = $value['haoma'];if (stripos($str, '-') !== FALSE) {    echo substr($str, stripos($str, '-') + 1);} else {    echo $str;}
Copy after login
Copy after login

1、

echo substr('057188885281-001',-3,3);
Copy after login


2、
echo substr($str,-3,3);
Copy after login

2、

$arr = explode('-', '057188885281-001'); echo $arr[1];
Copy after login

也可以用 stristr...

$str = '057188885281-001';$str = $value['haoma'];if (stripos($str, '-') !== FALSE) {    echo substr($str, stripos($str, '-') + 1);} else {    echo $str;}
Copy after login
Copy after login


--------------------------------------------

页面显示的格式是:
号码                          工号
057188885281                  001         ---这是带工号的
057188885281                              -- 没带工号的
13111113086                               -- 没带工号的
-----------------------------------------------
上面是我想实现的效果

------------------------------------------------
下面是你们给我的代码显示的效果

页面显示的格式是:
号码                          工号
057188885281-001            001         ---这是带工号的
057188885281                057188885281          -- 没带工号的
13111113086                 13111113086    -- 没带工号的





谢谢大家 我搞定了
代码贴出

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template