Forum Moderators: coopster

Message Too Old, No Replies

[url] tags in comments

         

rlkanter

7:44 pm on Feb 2, 2005 (gmt 0)

10+ Year Member


I've made a very simple site comment system for people to leave quick messages that anyone can view. Currently I convert all the html tags to their html code equivalents, but I'd like to allow people to post url's using something like [url].

I've already added support for [b] [/b] (for bold), but I haven't find an easy solution for:
[url]somesite[/url]
and possibly
[url]somesite[urlname]click here[/urlname][/url]

I've done some search's but the amount of results returned for url is huge. If anyone has a quick code snippet or a link to a site that show's how to do this that'd be great. Thanks :)

jusdrum

9:44 pm on Feb 2, 2005 (gmt 0)

10+ Year Member



Try this:

$Content = "This is a [link=http://www.example.com]link to my web site[/link]";

$Content = preg_replace("/\[link=\"(.*?)\"\](.*?)\[\/link\]/","<a href=\"$1\">$2</a>",$Content);

print($Content)

Result should be:

This is a <a href="http://www.example.com">link to my web site</a>

You should be able to replace link with url, I only changed it because the url tag is parsed in this message board.

dreamcatcher

11:30 pm on Feb 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This works for the [url][/url] tags:

<textarea name="data"></textarea>

$data = eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]", "<a href=\"\\1\">\\2</a>", $data);

rlkanter

7:36 am on Feb 3, 2005 (gmt 0)

10+ Year Member



Thank you both very much, that was exactly what I was looking for :)