Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/70638-solved-php-bb-code-using-perg-replace/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.