search
HomeBackend DevelopmentPHP TutorialPHP regular expression application to extract lyrics_PHP tutorial
PHP regular expression application to extract lyrics_PHP tutorialJul 13, 2016 pm 05:44 PM
phpgenerallyDownFunctionlyricsregularBaiduofexpressionmusic Box

前几天看了下百度音乐盒的功能,发现有歌词功能

PHP regular expression application to extract lyrics_PHP tutorial

  这里的歌词一般都是LRC格式的,是有时间的,如果想用作文本没有时间的话,文本里面的时间段就会成为了干扰障碍。

  下面是一首歌的Lrc歌词

[ti:听说][ar:刘若英][al:我的失败与伟大][by:活在当下][00:01.22]刘若英 - 听说[00:03.79]专辑名称:听说?[00:06.73]作词:葛大为 作曲:林健华[00:09.74][00:10.79]lrc制作:卜超  QQ:6313827[00:25.13][00:27.08]听说 你身边有新面孔[00:32.04]听说 你不再寂寞[00:35.33]听说 你提起我[00:38.73]我过得不错 忙碌中还有感动[00:45.38]尝试爱过几个人 面对爱 也诚实许多[00:52.86]只能被听说 安排着[00:56.91]关于你我的 对的或错的[00:60.00]两个人 曾经相似的 却以为都变了[01:06.18]只能靠听说 各自爱着[01:10.24]不需要证明 当时决定是错的[01:13.31]想着联络 不如心底远远问候[01:19.56]最美丽 莫过于听说你 还回忆[01:24.80]其实我也感激 当我听说你还相信爱情[01:45.82][01:47.83]听说 我巷口你常经过[01:52.76]听说 你厌倦寂寞[01:56.10]听说 你问候我[01:59.52]我过得不错 忙碌中还有感动[02:06.04]尝试爱过几个人 面对爱 也诚实许多[02:52.11][02:12.94][02:52.67][02:13.35]只能被听说 安排着[02:56.63][02:17.26]关于你我的 对的或错的[02:59.77][02:20.32]两个人 曾经相似的 却以为都变了[03:06.11][02:26.48]只能靠听说 各自爱着[03:10.07][02:30.56]不需要证明 当时决定是错的[03:13.10][02:33.62]想着联络 不如心底远远问候[03:19.31][02:39.88]最美丽 莫过于听说你 还回忆[03:24.58][02:45.12]其实我也感激 当我听说你还相信爱情[03:33.66][03:36.56]听说 我身边有新面孔[03:42.53]听说 你祝福了我[03:52.39][03:53.93]lrc制作:卜超  QQ:6313827  这里的时间段很有规律,一般以“[”开头以“]”结尾,有重复的时候就会出现两段时间段。第一时间想到了正则表达式,于是就用正则表达式写了如下的程序

                                 
";            preg_match_all("/][^[].*+/",$contents,$array);            $numArray = count($array[0]);            for($i = 0;$i";            }            echo "

这是处理后的歌词记录


";            echo $contents2;            echo "

这是未处理的歌词记录


";            echo "
";            echo "
";            print_r($array);            echo "
";        ?>   
  于是乎,终于看见一线完美的喜悦——

[ti:heard][ar:Rene Liu][al:my failure and greatness][by:live in the moment][00:01.22]Rene Liu - heard[00:03.79]Album name: heard? [00:06.73] Lyricist: Ge Dawei Composer: Lin Jianhua [00:09.74][00:10.79]lrc Producer: Bu Chao QQ:6313827[00:25.13][00:27.08]I heard there are new faces around you[00 ; 00:52.86]Can only be heard and arranged [00:56.91]What is right or wrong about you and me [00:60.00]Two people were once similar but thought they have changed [01:06.18]Can only be heard and heard We love each other [01:10.24] There is no need to prove that the decision made at that time was wrong [01:13.31] Thinking of contact is not as good as greetings from a distance in my heart [01:19.56] The most beautiful thing is to hear that you still remember [01:24.80] In fact, I I am also 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 that you greet me[01 :59.52]I’m doing well, I’m busy and I’m still touched [02:06.04] I’ve tried to love a few people and I’m much more honest when it comes to love [02:52.11][02:12.94][02:52.67][02:13.35] I can only It is said that arrangements are made[02:56.63][02:17.26]What is right or wrong about you and me[02:59.77][02:20.32]Two people were once similar but thought they have changed[03:06.11][ 02:26.48]We can only rely on hearing that we are in love with each other[03:10.07][02:30.56]There is no need to prove that the decision made at that time was wrong[03:13.10][02:33.62]It is better to say hello from afar than to contact each other[03 :19.31][02:39.88]The most beautiful thing is when I hear that you still remember it[03:24.58][02:45.12]In fact, I am also grateful when I hear that you still believe in love[03:33.66][03:36.56]Listen Say there are new faces around me [03:42.53] I heard you blessed me [03:52.39] [03:53.93] lrc production: Bu Chao QQ: 6313827 This is the processed lyrics record Liu Ruoying - I heard the album name: Listen explain? Lyricist: Ge Dawei Composer: Lin Jianhua lrc Producer: Bu Chao QQ: 6313827 I heard that there are new faces around you I heard that you are no longer lonely I heard that you mentioned me I am having a good life I am still busy I am still touched I have tried to love with a few people I have faced Love is also honest. There are many things that can only be heard and arranged. What is right or wrong about you and me? Two people who were once similar but thought they have changed can only rely on hearing that they are in love. There is no need to prove that the decision at that time was wrong. It is better to think about contact. The most beautiful greeting from far away in my heart is to hear that you still remember me. In fact, I am also grateful. When I heard that you still believed in love, I heard that you often passed by me in the alley. I heard that you were tired of loneliness. I heard that you greeted me. I am doing well. I am still busy. I have been moved and tried to love several people. I am also honest in the face of love. Many people can only be heard and heard about what is right or wrong about you and me. Two people who were once similar but thought they have changed can only rely on hearing that each of them loves each other without proof. The decision was wrong at that time, thinking that contact is not as good as greetings from a distance in my heart. The most beautiful thing is to hear that you still remember me. In fact, I am also grateful. When I heard that you still believed in love, I heard that there are new faces around me, and I heard that you blessed me. lrc production: Bu Chao QQ: 6313827 This is an unprocessed lyrics record array ([0] = & gt; Array ([0] = & gt;] [1] = & gt;] [2] = & gt;] [3] = & gt;] [4] => ] Liu Ruoying - Hearing and Listening [5] => ] Album name: Hearing and Listening [6] => ] Lyrics: Ge Dawei Composer: Lin Jianhua [7] => ] [8] = > ]lrc Produced by: Bu Chao QQ: 6313827 [9] => ] [10] => ]I heard there are new faces around you [11] => ]I heard you are no longer lonely [12] => ; ]I heard you mentioned me [13] => ]I’m doing well, I’m busy and I’m still touched [14] => ]I’ve tried to love a few people and I’m much more honest when it comes to love. [15] => ]I can only It was heard that arrangements were made [16] => ] What is right or wrong about you and me &nbs

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478763.htmlTechArticleA few days ago, I looked at the functions of Baidu Music Box and found that there is a lyrics function. The lyrics here are generally in LRC format. Yes, there is time. If you want to use it as text and there is no time, the text...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)