php 标点符号反转,PHP删除标点符号(无破折号)
我在stackoverflow上找到了下面的脚本,它用破折号替换了特殊字符,以便清理url构建.但是,它并没有做得很好,因为它用破折号替换标点符号,如下面的“坏”示例所示.所以,相反,我想特别标点符号不要被任何东西替换,只是被删除…没有空格,没有破折号.任何有关这方面的帮助将不胜感激.
例:
today's weather is hot!
好:
todays-weather-is-hot
坏:
today-s-weather-is-hot-
这个脚本做了不好的例子……如何让它做得好?
function slugUrl($string) {
$string = strtolower($string);
$string = preg_replace('/[^a-zA-Z0-9]/i','-',$string);
$string = preg_replace("/(-){2,}/",'$1',$string);
return $string;
}
解决方法:
那这个呢? (我刚刚删除了标点符号)
function slugUrl($string){
$string = strtolower($string);
$string = preg_replace('/[!?\']/','',$string);
$string = preg_replace('/[^a-zA-Z0-9]/i','-',$string);
$string = preg_replace("/(-){2,}/",'$1',$string);
return $string;
}
标签:php,replace,character
来源: https://codeday.me/bug/20190529/1180206.html
总结
以上是生活随笔为你收集整理的php 标点符号反转,PHP删除标点符号(无破折号)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 南芯推出 PD 3.1 快充 SoC S
- 下一篇: php fopen 汉字,PHP fop