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生成器的主要内容,如果未能解决你的问题,请参考以下文章
PHP 清理URL生成器的字符串
PHP如何在页面加载之前将查询字符串附加到URL
生成URL编码的查询字符串
如何在URL中带有特定字符串的页面/帖子中执行短代码?
上传到服务器后,Php生成了错误的格式url文件路径
PHP利用get_headers()函数判断远程的url地址是否有效