感谢您抽出时间阅读。
我有一个 MP3 文件文件夹,我想使用 PHP 来获取艺术家和标题,因为 ID3 标签不存在。
一个例子:
01。 Wham - Last Christmas.mp3
02。玛丽亚凯莉 - All I Want For Christmas Is You.mp3
03。创可贴 - 他们知道现在是圣诞节吗.mp3
我相信这是可能的,我只是对正则表达式不够 Eloquent 。
谢谢, jack 。
最佳答案
嗯,对于大多数情况,正则表达式
^\d+\. (.*) - (.*)\.mp3$
应该可以。
^ 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
您可以使用 preg_match
将字符串与正则表达式匹配功能:
$matches = array();
preg_match('/^\d+\. (.*) - (.*)\.mp3$/', "01. Wham - Last Christmas.mp3", $matches);
$artist = $matches[1];
$title = $matches[2];
关于php - 如何使用正则表达式从 MP3 文件名中获取艺术家和标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1843172/