Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使链接可从评论中单击_Php_Hyperlink_Chat_Anchor - Fatal编程技术网

在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开始就被弃用了。非常不鼓励依赖此功能。