Home > php教程 > php手册 > php使用substr()和strpos()联合查找字符串中某一特定字符的方法,substrstrpos

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

WBOY
Release: 2016-06-13 09:04:46
Original
1838 people have browsed it

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

本文实例讲述了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.bkjia.com/w3school/php/func_string_substr.htm
strpos()具体描述:http://www.bkjia.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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template