Regular expression application of refining Baidu lyrics implementation code

Time:2021-1-27

Regular expression application of refining Baidu lyrics implementation code
The lyrics here are generally in lrc format and have time. If you want to use the composition book without time, the time period in the text will become an interference barrier.
Here are the LRC lyrics of a song

Copy codeThe code is as follows:
[Ti: I heard]
[ar: Liu Ruoying]
[al: my failure and greatness]
[by: live in the moment]
[00:01.22] Liu Ruoying
[00:03.79] album title: heard?
[00:06.73] CI: Ge Dawei, composition: Lin Jianhua
[00:09.74]
[00:10.79] LRC made by: Bu Chao QQ: 6313827
[00:25.13]
[00:27.08] I heard you have a new face
[00:32.04] I heard that you are no longer lonely
[00:35.33] I heard you mentioned me
[00:38.73] I had a good time, and I was moved in my busy life
[00:45.38] I’ve tried to love a few people, and I’m more honest with love
[00:52.86] can only be arranged
[00:56.91] about you and me, right or wrong
[00:60.00] two people used to be similar, but they thought they had changed
[01:06.18] we can only rely on hearing that we love each other
[01:10.24] there is no need to prove that the decision was wrong
[01:13.31] far from the bottom of my heart, it’s better to keep in touch
[01:19.56] the most beautiful thing is to hear that you still remember
[01:24.80] actually, I’m grateful when I heard that you still believe in love
[01:45.82]
[01:47.83] I heard that you often pass by my alley
[01:52.76] I heard that you are tired of loneliness
[01:56.10] I heard you asked after me
[01:59.52] I had a good time, and I was moved in my busy life
[02:06.04] I’ve tried to love a few people, and I’m more honest with love
[02:52.11][02:12.94]
[02:52.67] [02:13.35] can only be arranged by hearing
[02:56.63] [02:17.26] about you and me, right or wrong
[02:59.77] [02:20.32] two people used to be similar, but they thought they had changed
[03:06.11] [02:26.48] we can only rely on hearing that we love each other
[03:10.07] [02:30.56] there is no need to prove that the decision was wrong
[03:13.10] [02:33.62] it’s better to greet from the bottom of my heart than to think about contact
[03:19.31] [02:39.88] the most beautiful thing is to hear that you still remember
[03:24.58] [02:45.12] actually, I’m grateful when I heard that you still believe in love
[03:33.66]
[03:36.56] I heard there are new faces around me
[03:42.53] I heard you blessed me
[03:52.39]
[03:53.93] LRC made by: Bu Chao QQ: 6313827

The time period here is very regular. It usually starts with “[” and ends with “]. When there is repetition, there will be two time periods. The first time I thought of regular expression, so I wrote the following program with 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 /><br />”;
preg_match_all(“/\][^\[].*+/”,$contents,$array);
$numArray = count($array[0]);
for($i = 0;$i<$numArray;$i++){
$contents2. = trim ($array [0] [$I], “\]); / / remove the left”] “
$contents2.=”<br />”;
}
Echo “< br / > < H2 > this is the processed lyrics record < / H2 > < br / >”;
echo $contents2;
Echo “< br / > < H2 > this is an unprocessed lyrics record < / H2 > < br / >”;
echo “<br />”;
echo “<pre>”;
print_r($array);
echo “</pre>”;
?>
</body>
</html>

So I finally saw a ray of perfect joy——

Copy codeThe code is as follows:
[Ti: I heard]
[ar: Liu Ruoying]
[al: my failure and greatness]
[by: live in the moment]
[00:01.22] Liu Ruoying
[00:03.79] album title: heard?
[00:06.73] CI: Ge Dawei, composition: Lin Jianhua
[00:09.74]
[00:10.79] LRC made by: Bu Chao QQ: 6313827
[00:25.13]
[00:27.08] I heard you have a new face
[00:32.04] I heard that you are no longer lonely
[00:35.33] I heard you mentioned me
[00:38.73] I had a good time, and I was moved in my busy life
[00:45.38] I’ve tried to love a few people, and I’m more honest with love
[00:52.86] can only be arranged
[00:56.91] about you and me, right or wrong
[00:60.00] two people used to be similar, but they thought they had changed
[01:06.18] we can only rely on hearing that we love each other
[01:10.24] there is no need to prove that the decision was wrong
[01:13.31] far from the bottom of my heart, it’s better to keep in touch
[01:19.56] the most beautiful thing is to hear that you still remember
[01:24.80] actually, I’m grateful when I heard that you still believe in love
[01:45.82]
[01:47.83] I heard that you often pass by my alley
[01:52.76] I heard that you are tired of loneliness
[01:56.10] I heard you asked after me
[01:59.52] I had a good time, and I was moved in my busy life
[02:06.04] I’ve tried to love a few people, and I’m more honest with love
[02:52.11][02:12.94]
[02:52.67] [02:13.35] can only be arranged by hearing
[02:56.63] [02:17.26] about you and me, right or wrong
[02:59.77] [02:20.32] two people used to be similar, but they thought they had changed
[03:06.11] [02:26.48] we can only rely on hearing that we love each other
[03:10.07] [02:30.56] there is no need to prove that the decision was wrong
[03:13.10] [02:33.62] it’s better to greet from the bottom of my heart than to think about contact
[03:19.31] [02:39.88] the most beautiful thing is to hear that you still remember
[03:24.58] [02:45.12] actually, I’m grateful when I heard that you still believe in love
[03:33.66]
[03:36.56] I heard there are new faces around me
[03:42.53] I heard you blessed me
[03:52.39]
[03:53.93] LRC made by: Bu Chao QQ: 6313827
This is the processed lyrics record
Liu Ruoying – listening and speaking
Album title: heard?
Composed by GE Dawei and Lin Jianhua
LRC production: Bu Chao QQ: 6313827
I hear you have a new face around you
I heard that you are no longer lonely
I heard you mentioned me
I had a good time, and I was moved by my busy life
Try to love a few people and be honest with love
It can only be arranged
About you and me, right or wrong
Two people used to be similar, but they thought they had changed
Only by hearing that they love each other
There is no need to prove that the decision was wrong
Thinking about contact is not as good as greeting from the bottom of my heart
The most beautiful is to hear that you still remember
In fact, I am also grateful when I heard that you still believe in love
I heard that you often pass by my alley
I hear you are tired of loneliness
I heard you asked after me
I had a good time, and I was moved by my busy life
Try to love a few people and be honest with love
It can only be arranged
About you and me, right or wrong
Two people used to be similar, but they thought they had changed
Only by hearing that they love each other
There is no need to prove that the decision was wrong
Thinking about contact is not as good as greeting from the bottom of my heart
The most beautiful is to hear that you still remember
In fact, I am also grateful when I heard that you still believe in love
I heard I have a new face around me
I heard you blessed me
LRC production: Bu Chao QQ: 6313827
This is an unprocessed record of lyrics
Array
(
[0] => Array
(
[0] => ]
[1] => ]
[2] => ]
[3] => ]
[4] = >] Liu Ruoying
[5] = >] album name: heard?
[6] = >] lyrics by GE Dawei and music by Lin Jianhua
[7] => ]
[8] = >] LRC production: Bu Chao QQ: 6313827
[9] => ]
[10] It’s said that there are new faces around you
[11] It is said that you are no longer lonely
[12] I heard you mentioned me
[13] = >] I had a good time. I was still moved in my busy life
[14] = >] I’ve tried to love a few people, and I’m a lot more honest in the face of love
[15] It can only be arranged by hearing
[16] What’s right or wrong about you and me
[17] They used to be similar, but they thought they had changed
[18] It’s only by hearing that we love each other
[19] = >] there is no need to prove that the decision was wrong
[20] = >] it’s better to keep in touch than to greet from the bottom of my heart
[21] = >] the most beautiful thing is to hear that you still remember
[22] = >] actually, I’m grateful when I heard that you still believe in love
[23] => ]
[24] = >] I heard that you often pass by my alley
[25] = >] I heard that you are tired of loneliness
[26] = >] I heard that you asked after me
[27] = >] I had a good time, and I was moved in my busy life
[28] = >] I’ve tried to love a few people, and I’m a lot more honest in the face of love
[29] => ]
[30] = >] can only be arranged by listening and speaking
[31] = >] about you and me, right or wrong
[32] = >] two people used to be similar, but they thought they had changed
[33] = >] we can only rely on hearing that we love each other
[34] = >] there is no need to prove that the decision was wrong
[35] = >] it’s better to greet from the bottom of my heart than to think about contact
[36] = >] nothing is more beautiful than hearing that you still remember
[37] = >] actually, I’m grateful when I heard that you still believe in love
[38] => ]
[39] = >] I heard that there are new faces around me
[40] = >] I heard that you blessed me
[41] => ]
[42] = >] LRC production: Bu Chao QQ: 6313827
)
)

Great success, regular expression to deal with this kind of problem is really easy to use, if you have better suggestions for this question, welcome to leave a message