supanoob Posted July 24, 2006 Share Posted July 24, 2006 well i have a function to change [ & ] to < & > but it doesnt seem to change the [/ & ] part at the end of the code. this is the function:[code]function tml ($topbody) { $topbody=htmlspecialchars($topbody); $topbody=str_replace('[b]','<b>',$topbody); return nl2br($topbody); }[/code]and whenever i type [ b] it works but whenever i put [/ b] it doesnt :S Link to comment https://forums.phpfreaks.com/topic/15531-str-functions/ Share on other sites More sharing options...
Barand Posted July 24, 2006 Share Posted July 24, 2006 [code]str_replace (array('[b]', '[/b]'), array('<b>', '</b>'), $topbody)[/code] Link to comment https://forums.phpfreaks.com/topic/15531-str-functions/#findComment-63093 Share on other sites More sharing options...
effigy Posted July 24, 2006 Share Posted July 24, 2006 ...or regex:[code]<?php echo preg_replace('%\[(/?b)\]%', "<$1>", '[b]This[/b] is bold.');?>[/code] Link to comment https://forums.phpfreaks.com/topic/15531-str-functions/#findComment-63097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.