PHP finds the specified string in a string and deletes the code

Source: Internet
Author: User
PHP in the string to find the specified string and delete the code, the web search is said, but the actual effect is not so good, or that the effect is not well


    
     $a = "abcababa"; $count=strpos($a,"ab"); $str=substr_replace($a,"",$count,2);var_dump($str);?>

The effect is as follows

OK, this may be the effect you want, but PHP's own function will solve the problem perfectly.
The code is as follows


    
     var_dump(str_replace("ab","","abcaasdfads"));?>

The official explanation is as follows
Grammar:
Str_replace (Find,replace,string,count)
Parameter description
Find: Required. Specifies the value to find.
Replace: Required. Specifies the value that replaces the value in Find.
String: Required. Specifies the string to be searched.
Count: Optional. A variable that counts the number of replacements.
In fact, the first is a small algorithm, can be limited to replace the number of characters, and the second is to replace all, according to the actual situation, the individual choice.

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes PHP in the string to find the specified string and delete the code, including the aspects of the content, I hope to be interested in PHP tutorial friends 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.