Php 使用HREF链接缩短URL

Php 使用HREF链接缩短URL,php,url,Php,Url,好的,我试图缩短一个url,但保持实际链接完整 我目前正在使用此代码,找不到简单的工作解决方案 $description = preg_replace('/https?:\/\/[^\s<]+/i', '<a href="\0">\0</a>', $description); $description=preg\u replace('/https?:\/\/[^\s尝试使用和 $url=parse\u url('http://www.example.com/839

好的,我试图缩短一个url,但保持实际链接完整

我目前正在使用此代码,找不到简单的工作解决方案

$description = preg_replace('/https?:\/\/[^\s<]+/i', '<a href="\0">\0</a>', $description);
$description=preg\u replace('/https?:\/\/[^\s尝试使用和

$url=parse\u url('http://www.example.com/839283ur9283ru2938u2389ru23irj3.html');
$newUrl=$url['scheme'].://'.$url['host'].substr($url['path'],0,8);
回声';

我需要它在描述中自动查找url链接,并使它们处于活动状态,同时将它们缩减到给定长度。
<a href="http://www.example.com/839283ur9283ru2938u2389ru23irj3.html">http://www.example.com/839283u...</a>
$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>';