PHP is used to delete any character in a string.

Source: Internet
Author: User
This article mainly introduces the PHP function for deleting any character in a string. it involves php's string traversal and truncation operations, and has some reference value, for more information about how to delete any character in a string using PHP, see the following example. Share it with you for your reference. The details are as follows:

Function delStr ($ start, $ end, $ orgenStr) {// read the first part of the string to be deleted, and assigned to $ temp // the position at which the strpos character is read for the first time. // substr reads the substring at the specified start and end positions. // echo $ before. "-". $ last; $ temp = $ orgenStr; while (strpos ($ temp, $ start) & strpos ($ temp, $ end) {$ temp = substr ($ temp, 0, strpos ($ temp, $ start )). substr ($ temp, strpos ($ temp, $ end) + strlen ($ end); // read the last part of the string to be deleted, and connect the front and back parts, and assign $ temp // return the final string} return $ temp;} // application instance $ a = "aaaa12345678bbbbtttttttttttttttttttttttaaaa12345678bbbb success"; $ B = "1234 "; $ c = "5678"; echo delStr ($ B, $ c, $ );

Output:

Bytes

PS:

Generally, applications have dynamic content in the middle of 1234 and 5678 and can be deleted in batches.

Update: Added loop deletion to delete all matching strings.

I hope this article will help you with php programming.

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.