感谢您抽出宝贵时间阅读.
我有一个MP3文件的文件夹,我想用PHP来获取Artist和Title,因为ID3标签不存在.
一个例子:
01. Wham - Last Christmas.mp3
02. Mariah Carey - All I Want For Christmas Is You.mp3
03. Band Aid - Do They Know It's Christmas Time.mp3
我确信这是可能的,我对正则表达式不够雄辩.
谢谢,杰克.
好吧,对于大多数情况下的正则表达式
^\d+\. (.*) - (.*)\.mp3$
Run Code Online (Sandbox Code Playgroud)
应该管用.
^ start of the string
\d+ at least one digit
\. a literal dot
(.*) the artist, in a capturing group. Matches arbitrary characters
until the following literal is encountered
- a literal space, dash, space
(.*) the title, in a capturing group
\.mp3 the file extension
$ end of the string
Run Code Online (Sandbox Code Playgroud)
您可以使用preg_match函数将字符串与正则表达式匹配:
$matches = array();
preg_match('/^\d+\. (.*) - (.*)\.mp3$/', "01. Wham - Last Christmas.mp3", $matches);
$artist = $matches[1];
$title = $matches[2];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2070 次 |
| 最近记录: |