Robkid Posted September 25, 2007 Share Posted September 25, 2007 Hello everyone, I have written a script that changes BB code to html but i cant for the life of me figure out how to change html back to bbcode here is what i am using: bbcode -----> html $story = "[b]Bold[/b] blah blah blah this isnt bold"; $bbcode = array('/\[br\]/is', '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[large\](.*?)\[\/large\]/is', '/\[small\](.*?)\[\/small\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[align\=(left|center|right)\](.*?)\[\/align\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[img name\=(.*?)\](.*?)\[\/img\]/is', '/\[mail\](.*?)\[\/mail\]/is', '/\[p\](.*?)\[\/p\]/is',); $html = array('<br />', '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<h2>$1</h2>', '<h3>$1</h3>', '<a href="$1">$2</a>', '<p align="$1">$2</p>', '<img src="$1" alt=""/>', '<img src="$2" alt="$1"/>', '<a href="mailto:$1">$1</a>', '<p>$1</p>',); $story = preg_replace ($bbcode, $html, $story); Any help on changing html to bbcode using perg replace would be great Thanks in advance, Robkid Quote Link to comment https://forums.phpfreaks.com/topic/70638-solved-php-bb-code-using-perg-replace/ Share on other sites More sharing options...
wildteen88 Posted September 25, 2007 Share Posted September 25, 2007 Why do you need to convert the html back into bbcode? It is best to convert the bbcode into html when it is needed, eg when being retrieved from the database and not when you insert it in to the database. Quote Link to comment https://forums.phpfreaks.com/topic/70638-solved-php-bb-code-using-perg-replace/#findComment-355104 Share on other sites More sharing options...
Robkid Posted September 26, 2007 Author Share Posted September 26, 2007 I am storing it as html because it is more effecient other wise i would have to call the bbcode to html function everytime i want to display my content this way i only have to call the content directly from the database saving the time and processing power but when someone wants to edit the content for instance it is nothing for me to call it there. Quote Link to comment https://forums.phpfreaks.com/topic/70638-solved-php-bb-code-using-perg-replace/#findComment-355434 Share on other sites More sharing options...
cooldude832 Posted September 26, 2007 Share Posted September 26, 2007 just an idea, and it hasn't been done that I have seen, but why not use BB->CSS using the BB tags and replace them with spans? Don't know if it helps or not or if its your plan, but to go back is harder because you be increase entropy as its called. Quote Link to comment https://forums.phpfreaks.com/topic/70638-solved-php-bb-code-using-perg-replace/#findComment-355439 Share on other sites More sharing options...
Robkid Posted September 26, 2007 Author Share Posted September 26, 2007 How would changing to css be any different a span is still and html tag so therefore i would still need to convert it back but it doesn't matter i have given up on being efficient and i am storing it in the database as BB code Quote Link to comment https://forums.phpfreaks.com/topic/70638-solved-php-bb-code-using-perg-replace/#findComment-355766 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.