3 回答
TA贡献1943条经验 获得超7个赞
您可以尝试以下具有正则表达式并按标签包装 URL 的代码。这适用于任何类型的 URL
<?php
//Regular Expression to filter urls
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
//your text
$projectDescription = "Some text..Link1: https://google.com/";
// Checking if any url is present in the text
if(preg_match($reg_exUrl, $projectDescription, $url)) {
// Wrap urls by <a>
$projectDescription = preg_replace($reg_exUrl, '<a href="'.$url[0].'">'.$url[0].'</a> ', $projectDescription);
}
echo $projectDescription;
?>
TA贡献1802条经验 获得超5个赞
尝试这个:
$projectDescription = "Some text..Link1: https://google.com/";
<p class="project-overview-text"><a href="your_link_here"><?php echo($projectDescription); ?></a></p>
TA贡献1789条经验 获得超10个赞
尝试这个?
<?php
$projectDescription = "Some text..Link1: https://google.com/";
$position_http = strpos($projectDescription,"http") ;
$position_com = strpos($projectDescription,"com") ;
$url = substr($projectDescription, $position_http, $position_com+2);
?>
<p class="project-overview-text"><?php echo substr($projectDescription, 0, $position_http);?>
<a href="<?php echo $url?>" class="project-overview-text"><?php echo($url); ?></a> </p>
在此处输入图像描述
- 3 回答
- 0 关注
- 165 浏览
添加回答
举报