如果我在一个文本框中输入一个链接,如果我们在某个页面上得到它的输出,它应该表现得像一个链接


If I enter a link in a textbox, it should behave like a link if we get its output on some page

我想创建一个文本框如果我在里面输入一个链接&通过PHP将这些数据插入mysql数据库;然后我在php页面上得到它的输出,它应该表现得像那个特定的链接。

,

<form>
<input type="" name="text" />
<input type="submit" value="submit" />
</form>

假设我在文本框&得到这个文本的输出,那么输出应该是http://stackoverflow.com,当点击应该带我到http://stackoverflow.com…

这个文本区域的stackoverflow.com我添加这个问题也就像我想要的…

如果有人知道请告诉我。

谢谢! !Muddser

用Markdown解析你的输出文本,我相信这是StackOverflow使用的一种风格。

<?php
require 'libs/markdown.php';
// do your database connection
$sql = "SELECT text FROM table WHERE id = 1 LIMIT 1";
$res = $db->query($sql);
$row = $res->fetch($res);
echo Markdown($row['text']);
if ($_POST['text']){
    preg_match_all('~((https?|ftp)://.*?) ~', $_POST['text'], $urls);
    foreach($urls[1] as $url){
        echo file_get_contents($url); // you can change echo to whatever you want
    }
}

并将方法改为POST

最好先去掉HTML标签:

strip_tags($field);

,然后将链接替换为HTML格式。你可以使用这个函数