感谢您抽出宝贵时间阅读.
我有一个MP3文件的文件夹,我想用PHP来获取Artist和Title,因为ID3标签不存在.
一个例子:
01. Wham – Last Christmas.mp3
02. Mariah Carey – 我想要的圣诞节是You.mp3
03.乐队援助 – 他们知道这是圣诞节Time.mp3
我确信这是可能的,我对正则表达式不够雄辩.
谢谢,
杰克.
解决方法:
好吧,对于大多数情况下的正则表达式
^\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];