我有这个 PHP 聊天框。
如果我在聊天框中键入链接,它不会将其显示为链接。
我如何使用 STR 替换来执行此操作?
它应该响应诸如“http”“http://”“.com”“.nl”“www”“www”之类的内容。 ....
我的其他 STR 替换行如下所示:
$bericht = str_replace ("STRING1","STRINGREPLACEMENT1",$bericht);
Someone?
嘿!试试这个代码(在 php.net 某处找到):
function format_urldetect( $text )
{
$tag = " rel=\"nofollow\"";
//
// First, look for strings beginning with http:// that AREN't preceded by an <a href tag
//
$text = preg_replace( "/(?<!<a href=(\"|'))((http|ftp|http)+(s)?:\/\/[^<>\s]+[\w])/i", "<a target=\"_new\" class=\"httplink\" href=\"\\0\"" . $tag . ">\\0</a>", $text );
//
// Second, look for strings with casual urls (www.something.com...) and make sure they don't have a href tag OR a http:// in front,
// since that would have been caught in the previous step.
//
$text = preg_replace( "/(?<!<a href=(\"|')http:\/\/)(?<!http:\/\/)((www)\.[^<>\s]+[\w])/i", "<a target=\"_new\" class=\"httplink\" href=\"http://\\0\"" . $tag . ">\\0</a>", $te
xt );
$text = preg_replace( "/(?<!<a href=(\"|')https:\/\/)(?<!http:\/\/)((www)\.[^<>\s]+[\w])/i", "<a target=\"_new\" class=\"httplink\" href=\"http://\\0\"" . $tag . ">\\0</a>", $t
ext );
return $text;
}
嗯,破损的缩进。尝试这个http://triop.se/code.txt http://triop.se/code.txt
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)