Tenaciousmug Posted May 25, 2012 Share Posted May 25, 2012 I'm trying to code a function that strips all BBCodes.. but I'm having trouble with the color since it has =whatever they type... This is how it looks: public function strip_bbcode($string) { // All the default bbcode arrays. $bbcode = array( //Text Apperence ' [center]' => '', '[/center] ' => '', '[b]' => '', '[/b]' => '', '[i]' => '', '[/i]' => '', '[u]' => '', '[/u]' => '', '[s]' => '', '[/s]' => '', ' [right]' => '', '[/right] ' => '', ' [left]' => '', '[/left] ' => '', '[small]' => '', '[/small]' => '', '[normal]' => '', '[/normal]' => '', '[big]' => '', '[/big]' => '', '[large]' => '', '[/large]' => '', '[color=(.*?)]' => '', '[url=(.*?)\](.*?)\[/url]#si' => '\\2', '[img]' => '', '[/img]' => '' ); $output = str_replace(array_keys($bbcode), array_values($bbcode), $string); return $output; } Anyone have any idea on how to do the color and the url?? I just basically want to replace it with emptiness. Link to comment https://forums.phpfreaks.com/topic/263098-replacing-bbcode-help/ Share on other sites More sharing options...
Tenaciousmug Posted May 25, 2012 Author Share Posted May 25, 2012 Figured it out. If anyone is curious, here is the solution: //removes bbcode public function strip_bbcode($string) { // All the default bbcode arrays. $bbcode = array( //Text Apperence '#\[b\](.*?)\[/b\]#si' => '\\1', '#\[i\](.*?)\[/i\]#si' => '\\1', '#\[u\](.*?)\[/u\]#si' => '\\1', '#\[s\](.*?)\[/s\]#si' => '\\1', '#\[center\](.*?)\[/center\]#si' => '\\1', '#\[right\](.*?)\[/right\]#si' => '\\1', '#\[left\](.*?)\[/left\]#si' => '\\1', //Font Color & Size '#\[color=(.*?)\](.*?)\[/color\]#si' => '\\2', '#\[small\](.*?)\[/small\]#si' => '\\1', '#\[normal\](.*?)\[/normal\]#si' => '\\1', '#\[big\](.*?)\[/big\]#si' => '\\1', '#\[large\](.*?)\[/large\]#si' => '\\1', //Text Effects '#\[bl\](.*?)\[/bl\]#si' => '\\1', '#\[marquee\](.*?)\[/marquee\]#si' => '\\1', //Other '#\[url=(.*?)\](.*?)\[/url]#si' => '\\2', '#\[quote\](.*?)\[/quote\]#si' => '\\1', '#\[img\](.*?)\[/img\]#si' => '\\1' ); $output = preg_replace(array_keys($bbcode), array_values($bbcode), $string); return $output; } Link to comment https://forums.phpfreaks.com/topic/263098-replacing-bbcode-help/#findComment-1348503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.