这是一个设计:例如,我把一个链接,如
在textarea.如何让PHP检测到它是一个http://链接,然后将其打印为
print "<a href='http://www.example.com'>http://www.example.com</a>";
我记得之前做过这样的事情,然而,这并不是为了复杂的链接而破坏它.
另一个好主意是如果你有一个链接,如
http://example.com/test.php?val1=bla&val2blablabla%20bla%20bla.bl
解决这个问题吧
print "<a href='http://example.com/test.php?val1=bla&val2=bla%20bla%20bla.bla'>";
print "http://example.com/test.php";
print "</a>";
这个只是一个想法.. stackoverflow也可能也使用这个:D
有任何想法吗
我希望能够在注释字段中获取用户输入的文本并检查URL类型表达式,如果存在,则在显示注释时添加锚标记(到url).
我在服务器端使用PHP,在客户端使用Javascript(使用jQuery),所以我应该等到它显示之前检查URL吗?或者在将锚标记插入数据库之前添加它?
所以
<textarea id="comment">check out blahblah.com or www.thisthing.co.uk or http://checkthis.us/</textarea>  
变
<div id="commentDisplay">check out <a href="blahblah.com">blahblah.com</a> or <a href="www.thisthing.co.uk">www.thisthing.co.uk</a> or <a href="http://checkthis.us/">http://checkthis.us/</a></div>
我想在链接尚未在链接中的字符串中查找 URL
我当前的代码:
$text = "http://www.google.com is a great website. Visit <a href='http://www.google.com' >http://google.com</a>"
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
if(preg_match($reg_exUrl, $text, $url)) {
   $links = preg_replace($reg_exUrl, '<a href="'.$url[0].'" rel="nofollow">'.$url[0].'</a>', $_page['content']['external_links']);
}
问题在于它返回了两次链接(这就是它返回的内容):
<a href="http://www.google.com" rel="nofollow">http://www.google.com</a> is a great website. Visit <a href='<a href="http://www.google.com" rel="nofollow">http://www.google.com</a>' ><a href="http://www.google.com" rel="nofollow">http://www.google.com</a></a>
我有一个用PHP编写的Web应用程序.我想在用户评论中找到所有网址,并将其更改为可点击的链接.我搜索了很多网站和页面,发现下面的解决方案(不幸的是我没有找到它的参考链接):
<?php
function convert($input) {
   $pattern = '@(http)?(s)?(://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])@';
   return $output = preg_replace($pattern, '<a href="http$2://$4">$0</a>', $input);
}
?>
这段代码完全归功于它的作者.但我发现其中有一个我无法解决的错误.
如果检测到的URL开始小号字母(无HTTPS),该HREF值不会有š性格和HTTP将变更为HTTPS,而内部的文字是正确的.  
示例:
 
source.com >><a href="https://ource.com">source.com</a>
你有解决这个bug的任何解决方案吗?
php ×4
preg-replace ×3
regex ×2
url ×2
html ×1
hyperlink ×1
javascript ×1
jquery ×1
linkify ×1
preg-match ×1