PHP implements a function that deletes any character in a string _php tips

Source: Internet
Author: User

The example in this article describes the PHP implementation function that deletes any character in the string. Share to everyone for your reference. Specifically as follows:

function Delstr ($start, $end, $orgenStr) 
{/ 
  /Read the first part of the string to delete the character position, and assign to the $temp  
  //strpos the position where the read character is to appear for the second time  
  Substr reads the substring//echo $before that specifies the start and end positions  
  . —". $last;  
  $temp = $orgenStr; 
  while (Strpos ($temp, $start) && Strpos ($temp, $end)) { 
  $temp =substr ($temp, 0, Strpos ($temp, $start)). substr ($temp, Strpos ($temp, $end) +strlen ($end)) 
  Reads the latter part of the string to remove the character position, and then joins the front and rear parts and assigns the value to $temp  
  //Returns the string at the end 
  $temp; 
Application instance  
$a = "aaaa12345678bbbbtttttttttttttttttttttaaaa12345678bbbb 
Kkkkkkkkkkkkaaaa12345678bbbbttttttttttttttttttttt "; 
$b = "1234"; 
$c = "5678"; 
Echo delstr ($b, $c, $a); 

The output is:

Aaaabbbbtttttttttttttttttttttaaaabbbbkkkkkkkkkkkkaaaabbbbttttttttttttttttttttt

Ps:

General applications in the middle of 1234 and 5678 have dynamic content, can be deleted in bulk

Update: A circular deletion was added to delete all eligible strings.

I hope this article will help you with your PHP program design.

Related Article

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.