Page 1 of 1
BB code
Posted: Tue Dec 13, 2011 2:57 am
by white04004
Hi guys!
I am facing another problem again. I am developing my custom blog system, and I want to add [url]
www.google.com[/url] and convert it into <a href="www.google.com">www.google.com</a>. How can I do that? I had tried substr(); but it doesn't work to url. Please help me. Thanks in advance.
Re: BB code
Posted: Tue Dec 13, 2011 12:29 pm
by Temor
white04004 wrote:Hi guys!
I am facing another problem again. I am developing my custom blog system, and I want to add
http://www.google.com and convert it into <a href="www.google.com">www.google.com</a>. How can I do that? I had tried substr(); but it doesn't work to url. Please help me. Thanks in advance.
What you want is BBcode. Pretty similar or identical to the one this forum uses, am I right?
Google BBCode and there are tonnes of free scripts and tutorials on how to implement them.
Re: BB code
Posted: Tue Dec 13, 2011 8:30 pm
by bowersbros
I think, since he is working on his own custom software, that he is doing it for practice. Therefore he would want to make it himself.
try something like this:
<?php
$string = "http://google.com/";
$match = preg_match("/^(|[url=])((https?|ftp|gopher|telnet|file ... -=\\\.&]*)/^","<a href='".$1."'>{$1}</a>",$string);
echo $match;
Try something like that, untested though.
Re: BB code
Posted: Tue Dec 13, 2011 9:43 pm
by EcazS
http://www.pixel2life.com/forums/index. ... ge__st__20
There are a lot of BB Parser code snippets that you can try out yourself.
Re: BB code
Posted: Thu Dec 29, 2011 1:26 am
by Chathu94
For any url :
$str = "your url here";
$str = preg_replace("\[[uU][rR][lL]\](.*?)\[/[uU][rR][lL]\]", "<a Href='$1'>$1</a>" ,$str);
Re: BB code
Posted: Sun Jan 01, 2012 1:21 am
by jacek
You can use the i modifier to make the expression case-insensitive
$str = preg_replace("#\[url\](.*?)\[/url]#i", "<a href='$1'>$1</a>" ,$str);
bit neater
Re: BB code
Posted: Sun Jan 01, 2012 5:04 am
by white04004
Thanks for your information. It works perfectly for me. Thanks a lot.