Jump to content

a little help needed with bbcode


Gruzin

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]
Link to comment
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]
Link to comment
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.
Link to comment
Share on other sites

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.