Table of Contents
CodeIgniter PHP 显示值截取-值
Jun 23, 2016 pm 02:38 PM
-----------------------
上面显示的值: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 -- 没带工号的
谢谢大家 我搞定了
代码贴出
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

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Simplified HTTP Response Mocking in Laravel Tests

Build a React App With a Laravel Back End: Part 2, React

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon
