Questions about using regular expressions to read article segments

Source: Internet
Author: User
About the use of regular expressions to read the segment of an article & lt; strong & gt; $ title = html_entity_decode ($ arrArticle ['title']); $ subtitle = html_entity_decode ($ arrArticle ['subtitle']); $ sourc questions about using regular expressions to read article segments
$ Title = html_entity_decode ($ arrArticle ['title']);
$ Subtitle = html_entity_decode ($ arrArticle ['subtitle']);
$ Source = html_entity_decode ($ arrArticle ['source']);
$ Author = html_entity_decode ($ arrArticle ['author']);
$ Intro = html_entity_decode ($ arrArticle ['Intro']);
$ Body = $ arrArticle ['content'];
$ Text = eregi_replace ('

',"

", $ Body );
$ Text = eregi_replace (" ] *>

"," ", $ Text );
$ Text = eregi_replace (" ] *)>
"," ", $ Text );
$ Body = stripslashes (str_replace ("

","

", $ Text ));
$ Body_arr = explode ("

", $ Body );
$ Body1 = $ body2 = $ body3 = '';
$ Total = count ($ body_arr );
$ Maxed = max (floor ($ total/2), 3 );

Foreach ($ body_arr as $ k => $ v ){
If ($ k = 0 ){
$ Body1 = $ v ."

";
} Else if ($ k <$ maxed ){
$ Body2. = $ v ."

";
} Else {
$ Body3. = $ v ."

";
}
}

This code matches the regular expression.

Section 1

Section 2

... To read the number of segments. However, there is a situation where some texts are segmented as follows:

Section 1

Section 2

Section 3

How can I write code for these two situations?

------ Solution --------------------
Discussion

PHP code
$ S ='

Section 1

Ss
Section 2

Section 3

';
$ Ar = preg_split ('/[<\/? P>
]/', $ S,-1, PREG_SPLIT_NO_EMPTY );
Print_r ($ ar );

PHP code
Array
(
[0] => First paragraph
[1] => ss
[2] => Second paragraph
[3 ......

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.