Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

convert bbcode to html

Links for php scripts

Moderators: macek, egami, gesf

convert bbcode to html

Postby glennn » Tue Jun 24, 2003 5:11 pm

i'm learning php and need to strip all the bbcode from a guestbook entry before it's posted to a flat file - i had one snippet, a small one, but i couldn't make it work wherever i put it in the script...

my write function is
[php]
$Input = "$message";

/* This combines the new data (the html code from above) with the old data (what was already in the .txt file. */
$New = "$Input";

/* This writes everything to the .txt file and then closes up the script. */
$filename = "caption.txt";
$fp = fopen( $filename,"w");
fwrite($fp, $New, 80000);
fclose( $fp );

[/php]

if you could tell me where the strip function needs to be placed, also...
thanks whoever can help...

glenn
glennn
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Jun 24, 2003 5:02 pm

Postby zeep25 » Wed Jun 25, 2003 3:45 pm

if u want to change the bbcode into html... this should fix your problem :

[php]

/*This will change the [b] into <b> */
$message=eregi_replace("\[B\]","<B>","$message");

/*This will change the [/b] into </b> */
$message=eregi_replace("\[/B\]","</B>","$message");


$Input = "$message";

/* This combines the new data (the html code from above) with the old data (what was already in the .txt file. */
$New = "$Input";

/* This writes everything to the .txt file and then closes up the script. */
$filename = "caption.txt";
$fp = fopen( $filename,"w");
fwrite($fp, $New, 80000);
fclose( $fp );

[/php]
zeep25
New php-forum User
New php-forum User
 
Posts: 9
Joined: Fri Mar 14, 2003 7:23 pm

Postby mike » Fri Jul 04, 2003 6:35 pm

Some adittional convertions:

Code: Select all
<?
$str = "Hello [color=cc3300]big [b]phpbrother[/b] this [u]is a[/u] fancy [i]test[/i][/color]";

//color convert
$str = str_replace("[color", "<font color", $str);
$str = str_replace("[/color]", "</font>", $str);

//bold,underline,italis convert
$str = str_replace("]", ">", $str);
$str = str_replace("[", "<", $str);

?>
User avatar
mike
New php-forum User
New php-forum User
 
Posts: 73
Joined: Sun May 04, 2003 4:26 am
Location: Athens


Return to PHP Scripts

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.