人们上网并提交一篇带有标题和描述的文章。人们经常包含链接,但它们显示为基本文本。我想要一种方式,当人们包含一个 url 时,它被识别为一个工作链接。我写了一个代码,但它只扫描一行,似乎在实际表中不起作用,因为它在表外回显。
基本上...我想要一个表格,当提交链接时,会生成一个超链接。有任何想法吗?下面这个更新的代码保持同样的事情发生。
我的代码如下:
$query = "SELECT * FROM rumours ORDER BY id DESC";
$query = mysql_query($query) or die('MySQL Query Error: ' . mysql_error( $connect ));
while ($row = mysql_fetch_assoc($query)) {
$id = $row['id'];
$band = $row['band'];
$title = $row['Title'];
$description = $row['description'];
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
// The Text you want to filter for urls
// Check if there is a url in the text
if(preg_match($reg_exUrl, $description, $url)) {
// make the urls hyper links
preg_replace($reg_exUrl, '<a href="'.$url[0].'">'.$url[0].'</a>', $description);
}
echo "<table border='1'>";
echo "<tr>";
echo "<td> $title </td>";
echo "</tr>";
echo "<tr>";
echo "<td class = 'td1'> $description </td>";
echo "</tr>";
echo "</table>";
}