在php中使链接可从评论中单击
可能重复:在php中使链接可从评论中单击,php,hyperlink,chat,anchor,Php,Hyperlink,Chat,Anchor,可能重复: 我正在尝试创建功能,让我的聊天室可以点击链接。。。。以下是我创建的函数 <?php //makes links starting with http clickable function makehttpclickable($text){ return preg_replace('!(((f|ht)tp://)[-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1">$1</
我正在尝试创建功能,让我的聊天室可以点击链接。。。。以下是我创建的函数
<?php
//makes links starting with http clickable
function makehttpclickable($text){
return preg_replace('!(((f|ht)tp://)[-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1">$1</a>', $text);
}
//makes links starting www. http clickable
function clickywww($www){
return preg_replace('!((www)[-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1">$1</a>', $www);
}
/function that gives me an error!
function clickydotcom($noob){
return preg_replace('!([-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)(\.com)!i'.'!([-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)(\.com)!f', '<a href="$1.com$f">$1.com</a>', $noob);
}
此代码将完成此操作
<?php
$input= "website is http://www.xyz.com";
$clickable = preg_replace('*(f|ht)tps?://[A-Za-z0-9\./?=\+&%]+*', '<a href="$0">$0</a>', $input);
echo $clickable;
?>
我已经根据上述解决方案在您的函数中做了一些修改。此代码将使ftp、http等链接可单击
<?php
function makehttpclickable($input){
return preg_replace('*(f|ht)tps?://[A-Za-z0-9\./?=\+&%]+*', '<a href="$0">$0</a>', $input);
}
?>
希望这有帮助ereg_replace
函数从PHP5.3.0开始就被弃用了。非常不鼓励依赖此功能。