A common method of intercepting string interception string by JS

Source: Internet
Author: User
1:explode Split string

eg

$str = XXX:ABC;

$ABC = Explode (': ', ' $str '); Obtained is an array of

echo $ABC [1]; Output ABC

Cons: Must know the split point, and the location of the required data

Advantages: Good understanding

2:str_replace replacing string Parts

eg

$str = ABCDEFG;

$ABC = Str_replace (' DEFG ', ' ', ' $str '); Replace the DEFG with empty

Echo $abc; Output ABC

Disadvantage: The replaced part must be known

Advantages: Good understanding

3:SUBSTR Calendar String

eg

$str = ABCDEFG;

$re = Array ();

for ($i = 0; $i < strlen ($STR); $i + +) {//convert $str to an array

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

}

echo $re [0]. $re [1]. $re [2]; Output ABC

Cons: Must know the entire string, inefficient

Advantages: Random Splicing

The above introduces the JS intercept string interception string commonly used methods, including the JS intercept string aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.