How can I split txt file by blank line

Source: Internet
Author: User
Ask how to split the TXT file by blank line,
Ask how to split the TXT file by blank line,
such as TXT file a.txt

The contents are as follows:
Oh, ah, yes.
Uh, uh,

111111
222222

Quack Gaga
Quack Gaga

There is a blank line in it, how to press the blank line to cut it into a paragraph of the string?
------to solve the idea----------------------
If it is a blank line to split it will find two lines (\ r \ n)
$str = ' 123
Defsf

Abc
1213

&* (
';
Print_r (Explode ("\n\r", $str)); Equivalent to Print_r (Explode ("\r\n\r\n", $str));
or use regular
Preg_match ('/[^.] +? (? =\r\n\r\n)/', $STR, $mat);
Print_r ($mat);
------to solve the idea----------------------
$s =<<< TXT
Oh, ah, yes.
Uh, uh,

111111
222222

Quack Gaga
Quack Gaga
TXT;

$a = Preg_split ("/([\r\n]+) \\1/", $s);
Print_r ($a);
Array
(
[0] Oh ah ah ah
Uh, uh,
[1] = 111111
222222
[2] = = Quack Gaga
Quack Gaga
)

  • 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.