Grego Posted July 2, 2007 Share Posted July 2, 2007 In the forums I'm making, I'm using BBcode. I have a table containing translations. For example, "" is translated to "<b>". This way, I can limit what my users can do to manipulate the page, obviously. Anyhow, I want to include [ code] tags, but I can't figure out a way to stop text inside [ code] tags from being converted through the table. Tell me if I haven't explained that properly/enough. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 2, 2007 Share Posted July 2, 2007 You can "protect" certain code by removing it while performing other procedures. If you're already used htmlentities() to convert such characters as <> to < and >, you can replace [ code ] ...[ /code ] with <1>, <2>, etc, perform the other translations, and restore the original code sections by replacing their placeholders. I've used something like this: <?php function save_code(&$index_ref,&$array_ref,$code) { $array_ref[$index_ref] = str_replace('\"','"',$code); return '<' . $i_ref++ . '>'; } $source = htmlentities($source); $saved_code = array(); $sc_index = 0; preg_replace(array( '|\[code\](.*?)\[/code\]|ie', // Remove and store stuff here '/other replacements/', '/<(\d+)>/e' // Restore it here ),array( 'save_code($sc_index,$saved_code,$1)', '....', '$saved_code[$1]' ),$source); ?> 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.