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? Link to comment https://forums.phpfreaks.com/topic/81544-tag-str_replace/ Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 Use preg_replace. Link to comment https://forums.phpfreaks.com/topic/81544-tag-str_replace/#findComment-414046 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 Link to comment https://forums.phpfreaks.com/topic/81544-tag-str_replace/#findComment-414048 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... Link to comment https://forums.phpfreaks.com/topic/81544-tag-str_replace/#findComment-414055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.