PHP 字符串到有效的url生成器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 字符串到有效的url生成器相关的知识,希望对你有一定的参考价值。

$string = "1@-This is a Random string£";

//not allowed chars
$pattern = '/[^\w\s]+/';
$replacement = '';
$url = preg_replace($pattern, $replacement, $string);

//change the space with -	
$not_allowed = array(" "); 
$url = strtolower(str_replace($not_allowed, "-", $url));

// result
$url = "1-this-is-a-random-string"

以上是关于PHP 字符串到有效的url生成器的主要内容,如果未能解决你的问题,请参考以下文章