php使用substr()和strpos()联合查找字符串中某一特定字符的方法_PHP

WBOY
Release: 2016-06-01 14:35:32
Original
1213 people have browsed it

本文实例讲述了php使用substr()和strpos()联合查找字符串中某一特定字符的方法。分享给大家供大家参考。具体分析如下:

要求:在下面的字符串中查找双竖线前面的字符,大多数清空下使用explode()函数,但项目过程中使用了太多的explode(),所以找到了下面的方法。

<&#63;php
 $str="admin||46cc468df60c961d8da2326337c7aa58||0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,";
 echo substr($str,0,strpos($str,"||"));
&#63;>
Copy after login

输出内容为admin。

substr()具体描述:http://www.bitsCN.com/w3school/php/func_string_substr.htm
strpos()具体描述:http://www.bitsCN.com/w3school/php/func_string_strpos.htm

希望本文所述对大家的php程序设计有所帮助。

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!