Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial CodeIgniter PHP 显示值截取-值

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 Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Introduction to the Instagram API

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

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 cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

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

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles