Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

a little help needed with bbcode

Recommended Posts

hi guys,
I'am trying to write a simple bbcode, but I don't know how to insert link or hyperlink.....
Hope someone can help me with that. URL is not working, it must be replaced, here is my code:

[code=php:0]<?php

$bbcode_string = "[bold]Bold Text[/bold] [italic]Italicized Text[/italic] [underline]Underlined Text[/underline] [URL=http://Link]Link[/URL]"; // $bbcode string

    $bbcode=array(
    "[bold]" => "<b>",
    "[/bold]" => "</b>",
    "[italic]" => "<i>",
    "[/italic]" => "</i>",
    "[underline]" => "<u>",
    "[/underline]" => "</u>",
    "[URL=http://" => "<a>",
    "]" => "<a>",
    "[/URL]" => "</a>",
    );
$bbcode_string = str_replace(array_keys($bbcode), array_values($bbcode), $bbcode_string);
?>[/code]

Share this post


Link to post
Share on other sites
You need to use regular expressions

Here is a general tutorial on regex: [url=http://weblogtoolscollection.com/regex/regex.php]http://weblogtoolscollection.com/regex/regex.php[/url]

These phpfreaks tutorials looks at using regex for bb code

[url=http://www.phpfreaks.com/tutorials/107/0.php]http://www.phpfreaks.com/tutorials/107/0.php[/url]

[url=http://www.phpfreaks.com/tutorials/123/0.php]http://www.phpfreaks.com/tutorials/123/0.php[/url]

Share this post


Link to post
Share on other sites
Yes, you'll be better of with regualar expressions, they are alot more powerful than str_replace, but they are little bit more complicated when you start. Have a look at [url=http://www.phpfreaks.com/forums/index.php/topic,101566.msg402102.html#msg402102]this post[/url] of a simple BBCode parser with regualar expressions.

Share this post


Link to post
Share on other sites

×

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.