PHP preg替换干净的url
此替换的最佳解决方案是什么?快速且优化 我的链接:PHP preg替换干净的url,php,regex,preg-replace,Php,Regex,Preg Replace,此替换的最佳解决方案是什么?快速且优化 我的链接: https://example.com/event/123/Kinda 不要在意2壮举。贾巴/乡村音乐(1990) 我想: https://example.com/event/123/Kinda-Dont-Care2-Feat-Jaba/Country-Music-1990 preg_replace(“??”和“-”,$strUrl) 编辑: $str1=“有点不在乎2专长。贾巴” $str2=“乡村音乐(1990)” 替换为: $str1=“
https://example.com/event/123/Kinda 不要在意2壮举。贾巴/乡村音乐(1990)
我想:
https://example.com/event/123/Kinda-Dont-Care2-Feat-Jaba/Country-Music-1990
preg_replace(“??”和“-”,$strUrl)代码>
编辑:
$str1=“有点不在乎2专长。贾巴”代码>
$str2=“乡村音乐(1990)”
替换为:
$str1=“Kinda-Dont-Care2-Feat-Jaba”代码>
$str2=“Country-Music-1990”
谢谢。试试这个
$string = "example.com/event/123/Kinda Don't Care2 Feat. Jaba/Country Music (1990)";
// remove all non alphanumeric characters except spaces
$clean = preg_replace('/[^a-zA-Z0-9\s]/', '', strtolower($html));
// replace one or multiple spaces into single dash (-)
$clean = preg_replace('!\s+!', '-', $clean);
echo $clean;
ref-可能的副本