A very important technique in PHP is to intercept characters of a specified length in a specified string. PHP can use the PHP pre-defined function substr () function to intercept the string to realize, believe that everyone is very clear, then I have those methods!
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)
Where start is the parameter
Positive number-starts at the specified position in the string
Negative number-starts at the specified position from the end of the string
0-Starts at the first character in a string
The code is as follows:
<?php Echo substr ("Hello world!", 6,5); ? >
Output World
The Strstr () function searches for the first occurrence of a string in another string.
The function returns the remainder of the string (from the matching point). returns false if the searched string is not found.
The code is as follows:
Strstr (' abc@jb51.net ', ' @ ', TRUE); The parameter sets true to return the header before the lookup value @ abcstrstr (' abc@jb51.net ', ' @ '); The default returns the tail after the lookup value @, @jb51. Net
Summarize:
I believe that everyone through the study of this article, the PHP interception of strings have a certain understanding and understanding, and hope that your work has helped!
Related recommendations:
PHP Intercept string function substr () function instance usage detailed
PHP intercept string (no garbled UTF8)
php intercept string function, PHP custom string interception method