Jump to content


Photo

a little help needed with bbcode


  • Please log in to reply
3 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 27 July 2006 - 08:56 AM

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:

<?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);
?>

I don't need your script, I'll try to write it myself

#2 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 27 July 2006 - 09:03 AM

You need to use regular expressions

Here is a general tutorial on regex: http://weblogtoolsco...regex/regex.php

These phpfreaks tutorials looks at using regex for bb code

http://www.phpfreaks...rials/107/0.php

http://www.phpfreaks...rials/123/0.php
If you're not part of the solution, you're part of the precipitate

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 July 2006 - 10:08 AM

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 this post of a simple BBCode parser with regualar expressions.

#4 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 27 July 2006 - 11:05 AM

ok, thanks guys:)
I don't need your script, I'll try to write it myself




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users