Home >Backend Development >PHP Tutorial >Introduction to the method of intercepting strings in php

Introduction to the method of intercepting strings in php

黄舟
黄舟Original
2017-11-15 09:27:482561browse

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)

Instance:


The code is as follows:

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

Output 6


The code is as follows :

substr(string,start,length)

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);  ?>

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

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!

Statement:
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