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
https://forums.phpfreaks.com/topic/58621-bb-code/
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
https://forums.phpfreaks.com/topic/58621-bb-code/#findComment-290782
Share on other sites

Archived

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

×
×
  • 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.