Implementation Code for extracting Baidu lyrics using regular expressions

Source: Internet
Author: User


Here, the lyrics are generally in LRC format and have time. If you want to use text without time, the time period in the text will become a disturbance obstacle.
Below is the Lrc lyrics of a song

Copy codeThe Code is as follows: [ti: I heard]
[Ar: Liu ruoying]
[Al: my failures and greatness]
[By: Live now]
[. 22] Liu ruoying-I heard
[00:03. 79] album name: Heard?
[. 73] compose: GE Dawei compose: Lin Jianhua
[00:09. 74]
[. 79] lrc: bu Chao QQ: 6313827
[:25. 13]
[. 08] I heard you have new faces.
[. 04] I heard that you are no longer lonely
[. 33] I heard you mentioned me
[. 73] I'm so touched when I'm busy.
[. 38] I tried to love a few people and I was honest with each other.
[. 86]
[. 91] You and I are right or wrong
[00: 60.00] Two people thought they had changed.
[. 18] You can only hear that you love each other.
[. 24] It is not necessary to prove that the decision was wrong.
[. 31] it's better to keep in touch with your heart and send greetings
[. 56] The most beautiful thing is to hear that you still recall
[. 80] In fact, I am also grateful when I heard that you still believe in love.
[. 82]
[. 83] I heard you often go through the streets.
[. 76] I heard you're tired of being lonely.
[. 10] I heard you greet me
[. 52] I'm so touched when I'm busy.
[. 04] I tried to love a few people and I was honest with each other.
[02: 52. 11] [02: 12. 94]
[. 67] [. 35]
[. 63] [. 26] About you and me
[. 77] [. 32] Two people once thought they both changed
[. 11] [. 48] You can only hear that you love each other.
[. 07] [. 56] You do not need to prove that the decision was wrong.
[. 10] [. 62] I think it is better to contact people and send greetings from the bottom of my heart.
[. 31] [. 88] The most beautiful thing is to hear that you still recall
[. 58] [. 12] In fact, I am also grateful when I heard that you still believe in love.
[3:33. 66]
[. 56] I heard that there are new faces around me
[. 53] I heard you blessed me.
[. 39]
[. 93] lrc: bu Chao QQ: 6313827

The time period here is quite regular. Generally, it starts with "[" and ends with "]". When there are duplicates, two time periods will appear. The first time I thought of the regular expression, I wrote the following program using the regular expression.Copy codeThe Code is as follows: <! DOCTYPE html>
<Html lang = "en">
<Head>
<Title> </title>
<Meta charset = "UTF-8"/>
<Meta name = "author" content = ""/>
<Meta name = "keywords" content = ""/>
<Meta name = "description" content = ""/>
</Head>
<Body>
<? Php
$ Contents2 = "";
$ Filename = "html/tingshuo. lrc ";
$ Contents = file_get_contents ($ filename );
Echo nl2br ($ contents );
Echo "<br/> ";
Preg_match_all ("/\] [^ \ []. * +/", $ contents, $ array );
$ NumArray = count ($ array [0]);
For ($ I = 0; $ I <$ numArray; $ I ++ ){
$ Contents2. = trim ($ array [0] [$ I], "\]"); // remove "]" on the left
$ Contents2. = "<br/> ";
}
Echo "<br/> Echo $ contents2;
Echo "<br/> Echo "<br/> ";
Echo "<pre> ";
Print_r ($ array );
Echo "</pre> ";
?>
</Body>
</Html>

Finally, I finally saw the perfect joy --Copy codeThe Code is as follows: [ti: I heard]
[Ar: Liu ruoying]
[Al: my failures and greatness]
[By: Live now]
[. 22] Liu ruoying-I heard
[00:03. 79] album name: Heard?
[. 73] compose: GE Dawei compose: Lin Jianhua
[00:09. 74]
[. 79] lrc: bu Chao QQ: 6313827
[:25. 13]
[. 08] I heard you have new faces.
[. 04] I heard that you are no longer lonely
[. 33] I heard you mentioned me
[. 73] I'm so touched when I'm busy.
[. 38] I tried to love a few people and I was honest with each other.
[. 86]
[. 91] You and I are right or wrong
[00: 60.00] Two people thought they had changed.
[. 18] You can only hear that you love each other.
[. 24] It is not necessary to prove that the decision was wrong.
[. 31] it's better to keep in touch with your heart and send greetings
[. 56] The most beautiful thing is to hear that you still recall
[. 80] In fact, I am also grateful when I heard that you still believe in love.
[. 82]
[. 83] I heard you often go through the streets.
[. 76] I heard you're tired of being lonely.
[. 10] I heard you greet me
[. 52] I'm so touched when I'm busy.
[. 04] I tried to love a few people and I was honest with each other.
[02: 52. 11] [02: 12. 94]
[. 67] [. 35]
[. 63] [. 26] About you and me
[. 77] [. 32] Two people once thought they both changed
[. 11] [. 48] You can only hear that you love each other.
[. 07] [. 56] You do not need to prove that the decision was wrong.
[. 10] [. 62] I think it is better to contact people and send greetings from the bottom of my heart.
[. 31] [. 88] The most beautiful thing is to hear that you still recall
[. 58] [. 12] In fact, I am also grateful when I heard that you still believe in love.
[3:33. 66]
[. 56] I heard that there are new faces around me
[. 53] I heard you blessed me.
[. 39]
[. 93] lrc: bu Chao QQ: 6313827
This is the processed lyrics record.
Liu ruoying-I heard
Album name: Heard?
Lyrics: GE Dawei compose: Lin Jianhua
Lrc production: bu Chao QQ: 6313827
I heard there are new faces around you
I heard that you are no longer lonely
I heard you mentioned me
I'm so touched when I'm busy.
I tried to love a few people and I was honest with each other.
It can only be heard and arranged
You and I are right or wrong
Two people thought they both changed.
It can only be heard that they love each other
No need to prove that the decision was wrong.
I think it's better to contact me than to greet me from the bottom of my heart
The most beautiful thing is to hear that you still recall
In fact, I am also grateful when I heard that you still believe in love.
I heard you often go through the streets
I heard you are tired of being lonely.
I heard you greet me
I'm so touched when I'm busy.
I tried to love a few people and I was honest with each other.
It can only be heard and arranged
You and I are right or wrong
Two people thought they both changed.
It can only be heard that they love each other
No need to prove that the decision was wrong.
I think it's better to contact me than to greet me from the bottom of my heart
The most beautiful thing is to hear that you still recall
In fact, I am also grateful when I heard that you still believe in love.
I heard there are new faces around me
I heard you blessed me.
Lrc production: bu Chao QQ: 6313827
This is an unprocessed lyrics record
Array
(
[0] => Array
(
[0] =>]
[1] =>]
[2] =>]
[3] =>]
[4] =>] Liu ruoying-I heard
[5] =>] album name: Heard?
[6] =>] compose: GE Dawei compose: Lin Jianhua
[7] =>]
[8] =>] lrc production: bu Chao QQ: 6313827
[9] =>]
[10] =>] I heard that you have new faces.
[11] =>] I heard that you are no longer lonely
[12] =>] I heard you mentioned me
[13] =>] I'm so busy and touched.
[14] =>] I tried to love a few people and I was honest with each other.
[15] =>]
[16] =>] You and I are right or wrong
[17] =>] Two people thought they had changed.
[18] =>] You can only hear that you love each other.
[19] =>] You do not need to prove that the decision was wrong.
[20] =>] thinking about contact is far from greeting me
[21] =>] The most beautiful thing is to hear that you still recall
[22] =>] In fact, I am also grateful when I heard that you still believe in love.
[23] =>]
[24] =>] I heard that you often go through the streets
[25] =>] I heard that you are tired of being lonely.
[26] =>] I heard you greet me
[27] =>] I'm so busy and touched.
[28] =>] I tried to love a few people and I was honest with each other.
[29] =>]
[30] =>]
[31] =>] You and I are right or wrong
[32] =>] Two people thought they had changed.
[33] =>] You can only hear that you love each other.
[34] =>] You do not need to prove that the decision was wrong.
[35] =>] thinking about contact is far from greeting me
[36] =>] The most beautiful thing is to hear that you still recall
[37] =>] I am also grateful when I heard that you still believe in love.
[38] =>]
[39] =>] I heard that there are new faces around me
[40] =>] I heard you blessed me.
[41] =>]
[42] =>] lrc: bu Chao QQ: 6313827
)
)

As a result, it is really easy to use regular expressions to handle such problems. If you have better suggestions for this question, please leave a message.

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.