PDA

View Full Version : replace links like in bbcode... with ereg_replace?


redhead
04-23-2003, 07:53 PM
greetings,

well... im pretty sure that i am slowly getting better at php and all;) (please refrain from saying what you really think:p)... but alas... am writing one of them blog-type-things for a friend of mine and he wants to be able to use something similar to bbcode for the links, as other poeple using the thing arnt familiar with html... etc etc

so... replaceing [ url=http://google.com]Google![/url] (without the spaces... i was sure this had an option to disable bbcode:() with <a href="http://google.com" target="_blank">Google!</a>

methinks it uses ereg_replace, and methinks that its been asked before, however i couldnt find anything after searching...

if you can help, that'd be grand :)

Ökii
04-23-2003, 08:43 PM
$txt_str = preg_replace("/\[url\=(.+?)\](.+?)\[\/url\]/is","<a href=\"$1\" target=\"_blank\">$2</a>",$txt_str);

redhead
04-23-2003, 10:09 PM
thanks okii.... muchly appriciated. preg_replace, eh? interesting. thanks again.