3 回答

TA貢獻1943條經(jīng)驗 獲得超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條經(jīng)驗 獲得超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條經(jīng)驗 獲得超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 關(guān)注
- 207 瀏覽
添加回答
舉報