search
HomeBackend DevelopmentPHP TutorialPHP regular expression application to extract lyrics_PHP tutorial

PHP regular expression application to extract lyrics_PHP tutorial

Jul 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 in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

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

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.