Forum Moderators: coopster

Message Too Old, No Replies

HTML to BBCode

preg_replace help needed

         

madk

2:13 am on Dec 7, 2007 (gmt 0)

10+ Year Member



Bah cant' edit title. It should read HTML -> BBCode

Hello all,

I need some help reversing this code. I am trying to pull some data from my db and then output it formatted with BBCode for editing. Any help would be appreciated. Thanks in advance.


$simple_search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[img\](.*?)\[\/img\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'#\[youtube\]([a-zA-Z0-9-_]+)\[/youtube\]#i');

$simple_replace = array(
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<center><img src = "$1"></center>',
'<a href="$1">$2</a>',
'<center><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/\1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object></center>');

$post = preg_replace($simple_replace, $simple_search, $post);

madk

2:18 am on Dec 7, 2007 (gmt 0)

10+ Year Member



Nevermind. Since I'm building the new system I found it is easier to store the data in the db as BBCode then parse it on display.

coopster

4:04 pm on Dec 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



However! What will you be doing more often?

Reading and displaying the data? Or updating the data?

Probably just read/display. You are going to be invoking a search/replace every time the information is requested. I think your original thought process was likely the better solution -- store it as you intend to use it most often.