好的,我试图缩短一个url,但保持实际链接不变。
我现在正在使用这段代码,找不到简单的工作解决方案。。。
$description = preg_replace('/https?:'/'/[^'s<]+/i', '<a href="'0">'0</a>', $description);
我想要实现的目标的例子。
输入http://www.example.com/839283ur9283ru2938u2389ru23irj3.html
输出http://www.example.com/839283u...
<a href="http://www.example.com/839283ur9283ru2938u2389ru23irj3.html">http://www.example.com/839283u...</a>
我需要它在描述中自动查找url链接并使其处于活动状态?同时将它们切割成给定的长度。
ty
尝试parse_url()和substr()
$url = parse_url('http://www.example.com/839283ur9283ru2938u2389ru23irj3.html');
$newUrl = $url['scheme'].'://'.$url['host'].substr($url['path'], 0, 8);
echo '<a href="'.$url.'">'.$newUrl.'...</a>';