Improve regular expression matching in preg_replace

Source: Internet
Author: User
This post was last edited by romy2008 from 2014-11-1420: 20: 28. & lt ;? Php $ body subtitle # e # & lt; p & nbsp; aligncenter & nbsp; & gt; & lt; img & nbsp; alt & nbs evaluate preg_replace regular expression matching

This post was last edited by romy2008 at 20:20:28

$ Body = 'subtitle # e #




"Sancheon Ling" is a publisher in Guangzhou and his real name is Li Ling. The pen name named "Sanchuan Ling" is used to commemorate the scenery in his hometown. I graduated from South China Normal University and worked as a journalist and editor for ten years in a magazine. I used to be one of the hot pushing pushes of health books. Like many working mothers, when she gave birth to her daughter six years ago, she began to pay attention to parenting issues and work in the publishing of children's books.


# P # never follow the big stream # e #


In a word, we should give priority to me and serve me with a service attitude. we should never follow the big stream, never go beyond our own economic capabilities, and never hold the magical attitude of early education, blindly choose an early education institution.


# P # assault learning for further studies # e #


  Fast-paced course before admission: for further studies, assault learning



With the increasing age of meatballs, I quickly found that there is a category ~ Early education classes for 6-year-olds are booming.


';

$ Body = preg_replace ('regularize', '', $ body );
Echo $ body;


// This is the content in DEDECMS. now I want to create a page for reading the full text, that is, this page is not paginated, and all the page tags in the content should be gone, the tags to be removed mainly include:
// 1. Mark "subtitle # e #" on the first page #"
// 2. Mark "# p # Do not follow the large stream # e #" in the middle of the page #"
// Note: # e # is the title, # p # Is the page, and the deletion also includes the # e # and # p # Characters.


?>


In this regard, xuzuning writes a regular expression
$ Body = preg_replace ('/(? : ^ | # P #).*? # E # \ s */S', '', $ body );

However, I have ignored a problem, that is, there is no "subtitle # e #" paging title at the beginning of the current section, for example:


$ Body ='




"Sancheon Ling" is a publisher in Guangzhou and his real name is Li Ling. The pen name named "Sanchuan Ling" is used to commemorate the scenery in his hometown. I graduated from South China Normal University and worked as a journalist and editor for ten years in a magazine. I used to be one of the hot pushing pushes of health books. Like many working mothers, when she gave birth to her daughter six years ago, she began to pay attention to parenting issues and work in the publishing of children's books.


# P # never follow the big stream # e #


In a word, we should give priority to me and serve me with a service attitude. we should never follow the big stream, never go beyond our own economic capabilities, and never hold the magical attitude of early education, blindly choose an early education institution.


# P # assault learning for further studies # e #


  Fast-paced course before admission: for further studies, assault learning



With the increasing age of meatballs, I quickly found that there is a category ~ Early education classes for 6-year-olds are booming.


';

$ Body = preg_replace ('regularize', '', $ body );
Echo $ body;


// This is the content in DEDECMS. now I want to create a page for reading the full text, that is, this page is not paginated, and all the page tags in the content should be gone, the tags to be removed mainly include:
// 1. Mark "subtitle # e #" on the first page #"
// 2. Mark "# p # Do not follow the large stream # e #" in the middle of the page #"
// Note: # e # is the title, # p # Is the page, and the deletion also includes the # e # and # p # Characters.


?>

In this way, the first page will be filtered out and improved. when there is no paging Title mark at the beginning of the section, the first page will not be deleted.
------ Solution ----------------------
I have observed that # p # and # e # are always in the same row.
Body = preg_replace ('/(? : ^
------ Solution ----------------------
# P #).*? # E # \ s */', '', $ body );

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.