我有一个简单的评论系统,人们可以在纯文本字段中提交超链接.当我将这些记录从数据库显示回网页时,我可以使用PHP中的RegExp将这些链接转换为HTML类型的锚链接吗?
我不希望算法使用任何其他类型的链接,只需http和https.
你能提供一个与Twitter用户名匹配的正则表达式吗?
如果提供Python示例,则额外奖励.
我想要:
Run Code Online (Sandbox Code Playgroud)Here is link: http://google.com And http://example.com inside. And another one at the very end: http://test.net
成为:
Run Code Online (Sandbox Code Playgroud)Here is link: <a href="http://google.com">http://google.com</a> And <a href="http://example.com">http://example.com</a> inside. And another one at the very end: <a href="http://test.net">http://test.net</a>
看起来像一个简单的任务,但我找不到一个有效的PHP函数.你有什么想法?
function make_links_clickable($text){
// ???
}
$text = 'Here is link: http://google.com
And http://example.com inside.
And another one at the very end: http://test.net';
echo make_links_clickable($text);
Run Code Online (Sandbox Code Playgroud) 我是新手.我想知道怎么做,因为我一直想和我的朋友开个玩笑.你能回答吗?谢谢!