conker87 Posted December 13, 2007 Share Posted December 13, 2007 I've got a article/review site and I'm wanting to add a little function to replace a custom tag (<wiki></wiki>) so that the enclosed text becomes a link to the said wikipedia page. Anyone got any ideas? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 Use preg_replace. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 13, 2007 Share Posted December 13, 2007 well preg_replace won't work perfectly because your replacements are probably dynamic look up BBCode replacements that should be similar Quote Link to comment Share on other sites More sharing options...
marcus Posted December 13, 2007 Share Posted December 13, 2007 $pattern = "/\[wiki\](.*?)\[\/wiki\]/is"; $replace = "<a href=\"http://en.wikipedia.org/wiki/$1\">$1</a>"; $string = "[wiki]Apple[/wiki]"; echo preg_replace($pattern,$replace,$string); You could try... Quote Link to comment 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.