Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中将部分url字符串转换为完整url链接_Php_Regex_Codeigniter_Url_Partial - Fatal编程技术网

如何在php中将部分url字符串转换为完整url链接

如何在php中将部分url字符串转换为完整url链接,php,regex,codeigniter,url,partial,Php,Regex,Codeigniter,Url,Partial,我有一个文本作为描述,例如“您好,这是我的网站,用于访问-http://www.abcxyz.com/testcontroller/testfunction“ 我需要将部分文本显示为描述的前70个字符,后跟“…” 所以部分文本的结果应该是“你好,这是我的网站,可以访问-”。但是,我需要将部分字符串转换为带有完整链接的URL 我已经使用正则表达式将字符串转换为url- function createUrlLink($text) { $url = '@(http)?(s)?(://)

我有一个文本作为描述,例如
“您好,这是我的网站,用于访问-http://www.abcxyz.com/testcontroller/testfunction“

我需要将部分文本显示为描述的前70个字符,后跟“…”

所以部分文本的结果应该是“你好,这是我的网站,可以访问-”。但是,我需要将部分字符串转换为带有完整链接的URL

我已经使用正则表达式将字符串转换为url-

function createUrlLink($text) {
        $url = '@(http)?(s)?(://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])@';
        $return_text = preg_replace($url, '<a href="http$2://$4" target="_blank" title="$0">$0</a>', $text);
        return $return_text;
    }
函数createUrlLink($text){
$url='@(http)?(s)?(:/)?([a-zA-Z])([-\w]+\)+([^\s\.]+[^\s]*)+[^,.\s])@;
$return\u text=preg\u replace($url,,$text);
返回$return\u文本;
}

这对于整个描述来说是很好的。但我需要得到这个部分字符串url的工作。有什么解决办法吗?

您必须通过正则表达式实现您的目标吗?为什么不使用文本溢出:css中元素的省略号?我认为这样做更容易,风险更小。除非您的字符串非常长,这可能会增加页面的加载时间,否则不确定though@japanGuy这对我来说真是个好办法。我将首先使用正则表达式将url字符串转换为url链接,然后应用此CSS。将检查加载的性能,但目前它可以工作。谢谢你,伙计!!!哦,我刚刚又读了一遍你的问题,意识到我误解了:)你能把这篇文章标记为已解决或者在顶部加一条注释吗?