hey there I relise there's probably a few threads on here but theres none that answer my question.

I have been writing a script for my web site where users can write in a thread and get the thread to display onto the main page, because this is done through a forum, I have to write up a bbcode script, I have some of the basic's done already however i'm stuck on the url's and email's could someone give me a hand?

here's the code I have so fare.

function bbcode($msg){
    //bold
    $msg = str_replace("[b]", "<b>", $msg);
    $msg = str_replace("[/b]", "</b>", $msg);
    //italic
    $msg = str_replace("[i]", "<i>", $msg);
    $msg = str_replace("[/i]", "</i>", $msg);
    //underline
    $msg = str_replace("[u]", "<u>", $msg);
    $msg = str_replace("[/u]", "</u>", $msg);
    //strikethrough
    $msg = str_replace("[s]", "<s>", $msg);
    $msg = str_replace("[/s]", "</s>", $msg);
    //marquee
    $msg = str_replace("[move]", "<marquee>", $msg);
    $msg = str_replace("[/move]", "</marquee>", $msg);
    //image
    $msg = str_replace("[img]", "<img src=\"", $msg);
    $msg = str_replace("[/img]", "\"/>", $msg);
    //table
    $msg = str_replace("[table]", "<table>", $msg);
    $msg = str_replace("[/table]", "</table>", $msg);
    $msg = str_replace("[tr]", "<tr>", $msg);
    $msg = str_replace("[/tr]", "</tr>", $msg);
    $msg = str_replace("[td]", "<td>", $msg);
    $msg = str_replace("[/td]", "</td>", $msg);
    $msg = str_replace("[th]", "<th>", $msg);
    $msg = str_replace("[/th]", "</th>", $msg);
    //list
    $msg = str_replace("[list]", "<ol>", $msg);
    $msg = str_replace("[/list]", "</ol>", $msg);
    $msg = str_replace("[li]", "<li>", $msg);
    $msg = str_replace("[/li]", "</li>", $msg);
    //preformatted text
    $msg = str_replace("[pre]", "<pre>", $msg);
    $msg = str_replace("[/pre]", "</pre>", $msg);

    //alignment
    $msg = str_replace("", "<div style='text-align:left'>", $msg);
    $msg = str_replace("", "</div>", $msg);  
    $msg = str_replace("", "<div style='text-align:center'>", $msg);
    $msg = str_replace("", "</div>", $msg);  
    $msg = str_replace("", "<div style='text-align:right'>", $msg);
    $msg = str_replace("", "</div>", $msg);  
    //HR
    $msg = str_replace("[hr]", "<hr>", $msg);    
    //script
    $msg = str_replace("[sub]", "<sub>", $msg);
    $msg = str_replace("[/sub]", "</sub>", $msg);
    $msg = str_replace("[sup]", "<sup>", $msg);
    $msg = str_replace("[/sup]", "</sup>", $msg);
    //teletype
    $msg = str_replace("[tt]", "<tt>", $msg);
    $msg = str_replace("[/tt]", "</tt>", $msg);
    //quote
    $msg = str_replace("[quote]", "<div class='quoteheader'>Quote</div><div class='quote'>", $msg);
    $msg = str_replace("[/quote]", "</div>", $msg);
    //Smiley's
    $msg = str_replace("::)", "<img src='http://pagancentral.org/smf/Smileys/default/rolleyes.gif'>", $msg);
    $msg = str_replace(":)", "<img src='http://pagancentral.org/smf/Smileys/default/smiley.gif'>", $msg);
    $msg = str_replace(";)", "<img src='http://pagancentral.org/smf/Smileys/default/wink.gif'>", $msg);
    $msg = str_replace(":D", "<img src='http://pagancentral.org/smf/Smileys/default/cheesy.gif'>", $msg);
    $msg = str_replace(";D", "<img src='http://pagancentral.org/smf/Smileys/default/grin.gif'>", $msg);
    $msg = str_replace(">:(", "<img src='http://pagancentral.org/smf/Smileys/default/angry.gif'>", $msg);
    $msg = str_replace(":(", "<img src='http://pagancentral.org/smf/Smileys/default/sad.gif'>", $msg);
    $msg = str_replace(":o", "<img src='http://pagancentral.org/smf/Smileys/default/shocked.gif'>", $msg);
    $msg = str_replace("8)", "<img src='http://pagancentral.org/smf/Smileys/default/cool.gif'>", $msg);
    $msg = str_replace("???", "<img src='http://pagancentral.org/smf/Smileys/default/huh.gif'>", $msg);
    $msg = str_replace("::)", "<img src='http://pagancentral.org/smf/Smileys/default/rolleyes.gif'>", $msg);
    $msg = str_replace(":P", "<img src='http://pagancentral.org/smf/Smileys/default/tongue.gif'>", $msg);
    $msg = str_replace(":-[", "<img src='http://pagancentral.org/smf/Smileys/default/embarrassed.gif'>", $msg);
    $msg = str_replace(":-X", "<img src='http://pagancentral.org/smf/Smileys/default//lipsrsealed.gif'>", $msg);
    $msg = str_replace(":-*", "<img src='http://pagancentral.org/smf/Smileys/default/kiss.gif'>", $msg);
    $msg = str_replace(":'(", "<img src='http://pagancentral.org/smf/Smileys/default/cry.gif'>", $msg);


 return ($msg);

any help would be appreciated.

Recommended Answers

All 3 Replies

Member Avatar for diafol

You've messed up the code with bbcode!

urls have at least 2 elements: href and the content. So a bbcode for an url would be:

replace url=href with <a href="href"> and the ending /url with </a>

hey there, that works kinda, but when I put the code in and view it on a beta page it only links to http:// or gives out a link back to my test folder where I store my test scripts. and not where it should go to in the thread.

Member Avatar for diafol

what's your code for this transformation?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.