我有这段正则表达式,用于从输入到文本区域的 URL 创建可点击的链接。我没有编写代码,也不知道如何修改它,以便在文本以 http 或 https 开头时它将创建链接。
$html = preg_replace('"\b(http://\S+)"', '<a href="$1">$1</a>', stripslashes($rows['body']));
最佳答案
向正则表达式添加 ?
使前面的字符可选。
$html = preg_replace('"\b(https?://\S+)"', '<a href="$1">$1</a>', stripslashes($rows['body']));
关于php - 如何修改此正则表达式以包含 https?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6091351/