Home > Backend Development > PHP Tutorial > JS intercepts strings. Common methods for intercepting strings.

JS intercepts strings. Common methods for intercepting strings.

WBOY
Release: 2016-07-28 08:30:01
Original
1850 people have browsed it

1: explode splits the string

eg:

$str = xxx:abc;

$abc = explode(':','$str'); //What is obtained is an array

echo $abc[ 1]; //Output abc

Disadvantages: You must know the split point and the location of the required data

Advantages: Easy to understand

2: str_replace replaces the string part

eg:

$str = abcdefg;

$abc = str_replace('defg','','$str'); //Replace defg with empty

echo $abc; //Output abc

Disadvantages: The replaced part must be known

Advantages: Good Understanding

3: substr traverses the string

eg:

$str = abcdefg;

$re = array();

for($i = 0;$i < strlen($str); $ i++){ //Convert $str into an array

$re[] = substr($str,$i,1);

}

echo $re[0].$re[1].$re[ 2]; //Output abc

Disadvantages: Must know the entire string, low efficiency

Advantages: Splicing at will

The above introduces the common methods of intercepting strings with js, including the content of intercepting strings with js. I hope it will be helpful to friends who are interested in PHP tutorials.

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