Jump to content

BB Code!


xyn

Recommended Posts

Hey Guys.

I basically made a short vesion of a BB Code...

It works perfectly, except i have came across a problem

basically when i use.. [ URL ]  [/ URL ] (without spaces)

and try and place an Image tag in there

i get the following....

<a href="weburl.com/tutorials/<img src=">">Link</a>

 

Anyone know how i can use 1 url for both the URL and IMAGE src?

 

code

<?php
$bb_codes = array(
   # bold
  '[b]' => '<span style="font-weight:bold">',
  '[/b]' => '</span>',
    # italic
  '[i]' => '<span style="font-style:italic">',
  '[/i]' => '</span>',
    # underline
  '[u]' => '<span style="text-decoration:underline">',
  '[/u]' => '</span>',
    # bold
  '[b]' => '<span style="font-weight:bold">',
  '[/b]' => '</span>',
    # italic
  '[i]' => '<span style="font-style:italic">',
  '[/i]' => '</span>',
    # underline
  '[u]' => '<span style="text-decoration:underline">',
  '[/u]' => '</span>',
    # added
'[img]' => '<img src="',
'[/img]' => '" border=0>',
'[img]' => '<img src="',
'[/img]' => '">',
'[url]' => '<a href="',
'[/url]' => '">Link</a>',
'[url]' => '<a href="',
'[/url]' => '">Link</a>',
'
[center]' => '<div align=center>',
'[/center]
' => '</div>',
'[mail]' => '<a href=mailto:"',
'[/mail]' => '">Email</a>',
'[color=Red]' => '<font color=red>',
'[/color]' => '</font>',
'[color=Blue]' => '<font color=blue>',
'[/color]' => '</font>',
'[color=Purple]' => '<font color=purple>',
'[/color]' => '</font>',
'[color=Yellow]' => '<font color=yellow>',
'[/color]' => '</font>',
'[color=Default]' => '<font color=black>',
'[/color]' => '</font>',
'[color=Green]' => '<font color=green>',
'[/color]' => '</font>',
'[codde]' => '<center><div id="code" style="background-color: #2C4A61; width:350px; overflow:auto"><code>',
'[/codde]' => '</code></div></center>',
'[quote]' => '<center><div id="quote" style="width:350;overflow:auto">',
'[/quote]' => '</div></center>',
    # smilies
  '' => '<img src="">',
  '' => '<img src="">',
  ':s' => '<img src="">',
  '' => '<img src="">',
  '' => '<img src="">',
  '' => '<img src="">',
  ':$' => '<img src="">',
  '' => '<img src="">',
  'X)' => '<img src="">',
  ':@' => '<img src="">',
  ':|' => '<img src="">'
);

function BBcode($t) 
{
$search = array_keys($GLOBALS['bb_codes']);
$t = str_ireplace($search, $GLOBALS['bb_codes'], $t);
return $t;
}
?>

Link to comment
Share on other sites

You would have to do a check inside the url tag for the image tag. If there is an image tag you want to parse the image portion first, than you want to parse the url portion around the img tag.

 


[url=http://www.test.com][img=http://www.testimage.jpg][/url]

 

Would be more or less how it needs to be setup. If you want it to link to the same I would suggest doing a new bbcode

 


[iurl=http://www.testimage.jpg][/iurl]

 

Thats what I would do and than use that to create a link like so:

 

<a href="http://www.testimage.jpg"><img src="http://www.testimage.jpg" /></a>

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.