我想能够获取用户在评论字段中输入的文本,并检查是否存在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>
http://blahblah.com
等形式。 - BalusC