Introduction to the method of intercepting strings in php

黄舟
Release: 2023-03-17 14:14:01
Original
2532 people have browsed it

There is a very important technology in php, which is to intercept characters of a specified length in a specified string . PHP can use the PHP pre-defined function substr() function to intercept strings. I believe everyone is very clear about this, so what other methods do I have?

The code is as follows:

strpos(string,find,start)
Copy after login

Instance:


The code is as follows:

<?php  echo strpos("Hello world!","wo");  ?>
Copy after login

Output 6


The code is as follows :

substr(string,start,length)
Copy after login

The parameter of start

Positive number - starts at the specified position of the string

Negative number - starts at the specified position from the end of the string
0 - at the specified position of the string Starting at the first character in

The code is as follows:

<?php  echo substr("Hello world!",6,5);  ?>
Copy after login

Output world

strstr() function

SearchA string in The first occurrence in another string.

This function returns the rest of the string (from the matching point). Returns false if the searched string is not found.


The code is as follows:

strstr(&#39;abc@jb51.net&#39;, &#39;@&#39;, TRUE); //参数设定true, 返回查找值@之前的首部,
abcstrstr( &#39;abc@jb51.net&#39;, &#39;@&#39;); //默认返回查找值@之后的尾部,@jb51.net
Copy after login

Summary:

I believe that by studying this article, you will be able to intercept PHP I have a certain understanding and understanding of strings, I hope it will be helpful to your work!

Related recommendations:

PHP interception string function substr() function example usage detailed explanation

php intercepts string (no garbled utf8)

php intercepts string function, php customString interceptionMethod

The above is the detailed content of Introduction to the method of intercepting strings in php. For more information, please follow other related articles on the PHP Chinese website!

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