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.
BB code
Re: BB code
What you want is BBcode. Pretty similar or identical to the one this forum uses, am I right?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.
Google BBCode and there are tonnes of free scripts and tutorials on how to implement them.
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: BB code
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:
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.
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: BB code
http://www.pixel2life.com/forums/index. ... ge__st__20
There are a lot of BB Parser code snippets that you can try out yourself.
There are a lot of BB Parser code snippets that you can try out yourself.
Re: BB code
For any url :
$str = "your url here"; $str = preg_replace("\[[uU][rR][lL]\](.*?)\[/[uU][rR][lL]\]", "<a Href='$1'>$1</a>" ,$str);
Last edited by jacek on Sun Jan 01, 2012 1:19 am, edited 2 times in total.
Reason: code tags...
Reason: code tags...
Re: BB code
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
-
- Posts: 4
- Joined: Tue Dec 06, 2011 5:41 pm
- Contact:
Re: BB code
Thanks for your information. It works perfectly for me. Thanks a lot.