vikramy Posted December 25, 2009 Share Posted December 25, 2009 Hello Everyone, I am a bit new to php already loving it. I am stuck in this can any one help me in this. I am having a pattern like this [url http://www.example.com]Test[/url] I need it to replace like this <a href="http://www.example.com">Test</a> Any help is really appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/186314-preg_replace/ Share on other sites More sharing options...
.josh Posted December 25, 2009 Share Posted December 25, 2009 You should try out the search function, there are literally thousands of threads asking this exact same thing, even with the same bbcode style tag. Quote Link to comment https://forums.phpfreaks.com/topic/186314-preg_replace/#findComment-983914 Share on other sites More sharing options...
vikramy Posted December 25, 2009 Author Share Posted December 25, 2009 Thanks you.. I searched and I think I almost found what I need. $replaced = [url http://www.example.com]Test[/url] $replaced = preg_replace ('/\[url(.*?)\](.*?)\[\/url\]/is','<a href="$1">$2</a>', $replaced); Thanks again. I haven't tested fully but this helps a lot.. Quote Link to comment https://forums.phpfreaks.com/topic/186314-preg_replace/#findComment-983919 Share on other sites More sharing options...
vikramy Posted January 29, 2010 Author Share Posted January 29, 2010 I have strange requirements like these. hope many have answers. [url http://www.gmail.com]Gmail[/url] should give Gmail which should point to http://www.gmail.com. And also if I type http://www.gmail.com it should be a link. The first one I could solve easily. but I need that in combination. Quote Link to comment https://forums.phpfreaks.com/topic/186314-preg_replace/#findComment-1003931 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.