[英]How to replace words from a phrase in PHP?
I have couple of mp3 files named 01 - Saanson Ko (Zid) - 128Kbps.mp3
and 01 - Saanson Ko (Zid) - 320Kbps.mp3
我有几个名为
01 - Saanson Ko (Zid) - 128Kbps.mp3
的mp3文件和01 - Saanson Ko (Zid) - 320Kbps.mp3
I want it to be renamed to 01 - Saanson Ko (Zid) - Muzic.Asia
I tried the following code but it did not work. 我希望将其重命名为
01 - Saanson Ko (Zid) - Muzic.Asia
我尝试了以下代码,但没有用。 How to do it? 怎么做?
$file = "01 - Saanson Ko (Zid) - 128Kbps.mp3";
$file = "01 - Saanson Ko (Zid) - 320Kbps.mp3";
$mp3_filename = str_replace(".mp3","",$file);
$mp3_filename = str_replace("128Kbps","Muzic.Asia",$file);
$mp3_filename = str_replace("320Kbps","Muzic.Asia",$file);
echo "$file";
str_replace()
returns the results. str_replace()
返回结果。
Try these codes : 尝试以下代码:
$file = "01 - Saanson Ko (Zid) - 128Kbps.mp3";
$file = "01 - Saanson Ko (Zid) - 320Kbps.mp3";
$file = str_replace(".mp3","",$file);
$file = str_replace("128Kbps","Muzic.Asia",$file);
$file = str_replace("320Kbps","Muzic.Asia",$file);
echo "$file";
This should work for you: 这应该为您工作:
You can use preg_replace()
and capture the parts which you want and replace it with Muzic.Asia
, eg 您可以使用
preg_replace()
并捕获所需的零件,并用Muzic.Asia
替换它,例如
$file = preg_replace("/ - \d+\w+\.\w+$/", " - Muzic.Asia", $file);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.