PHP uses substr() and strpos() to jointly find a specific character in a string, substrstrpos_PHP tutorial

WBOY
Release: 2016-07-13 09:54:07
Original
1352 people have browsed it

php uses substr() and strpos() to jointly find a specific character in a string, substrstrpos

The example in this article describes the use of substr() and strpos() in php A method to jointly find a specific character in a string. Share it with everyone for your reference. The specific analysis is as follows:

Requirement: Find the characters before the double vertical bar in the string below. Most of the clearing uses the explode() function, but too many explode()s were used during the project, so the following method was found.

<&#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

The output content is admin.

Detailed description of substr(): http://www.bkjia.com/w3school/php/func_string_substr.htm
Detailed description of strpos(): http://www.bkjia.com/w3school/php/func_string_strpos.htm

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/998548.htmlTechArticlephp uses substr() and strpos() to jointly find a specific character in a string, substrstrpos Example of this article Describes how PHP uses substr() and strpos() to jointly find a specific word in a string...
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!