bbcode

5 posts Page 1 of 1
Contributors
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

bbcode
Dummy1912
hello,

seems we have a error and i don't know how to fix it :(

anyone?

Fatal error: Cannot redeclare bbcode() on line 37
Code: Select all
<?php
function bbcode($str) { ///this is line 37

return $str;
}

echo ''.bbcode($fetch['comment']).'';

?>
Image

so you guys can see it works
but then when the second record must show i get this error :(

thanks
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: bbcode
CodenStuff
Looks fine to me :? ..Can you show us the whole code so we can see what is going on?
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: bbcode
Dummy1912
CodenStuff wrote:
Looks fine to me :? ..Can you show us the whole code so we can see what is going on?
Code: Select all

if(!empty($fetch['comment']))
{
	
  if($fetch['alerts']==0) {

echo '<div class="c_cont">';


function bbcode($str) {
  // delete 'http://' because will be added when convert the code
  $str = str_replace('[url=http://', '[url=', $str);
  $str = str_replace('[url]http://', '[url]', $str);

  // Array with RegExp to recognize the code that must be converted
  $bbcode_smiles = array(
    // RegExp for [b]...[/b], [i]...[/i], [u]...[/u], [block]...[/block], [color=code]...[/color], [br]
    '/\[b\](.*?)\[\/b\]/is',
    '/\[i\](.*?)\[\/i\]/is',
    '/\[u\](.*?)\[\/u\]/is',
    '/\[block\](.*?)\[\/block\]/is',
    '/\[color=(.*?)\](.*?)\[\/color\]/is',
    '/\[br\]/is',

    // RegExp for [url=link_address]..link_name..[/url], or [url]..link_address..[/url]
    '/\[url\=(.*?)\](.*?)\[\/url\]/is',
    '/\[url\](.*?)\[\/url\]/is',

    // RegExp for [img=image_address]..image_title[/img], or [img]..image_address..[/img]
    '/\[img\=(.*?)\](.*?)\[\/img\]/is',
    '/\[img\](.*?)\[\/img\]/is',

    // RegExp for sets of characters for smiles: :), :(, :P, :P, ...
    '/:\)/i', '/:\(/i', '/:P/i', '/:S/i', '/:O/i', '/=D\>/i', '/\>:D\</i', '/:D/i', '/:-\*/i'
  );

  // Array with HTML that will replace the bbcode tags, defined inthe same order
  $html_tags = array(
    // <b>...</b>, <i>...</i>, <u>...</u>, <blockquote>...</blockquote>, <span>...</span>, <br/>
    '<b>$1</b>',
    '<i>$1</i>',
    '<u>$1</u>',
    '<blockquote>$1</blockquote>',
    '<span style="color:$1;">$2</span>',
    '<br/>',

    // a href...>...</a>, and <img />
    '<a target="_blank" href="http://$1">$2</a>',
    '<a target="_blank" href="http://$1">$1</a>',
    '<img src="$1" alt="$2" />',
    '<img src="$1" alt="$1" />',

    // The HTML to replace smiles. Here you must add the address of the images with smiles
    '<img src="img/smileys2/1.gif" alt=":)" border="0" />',
    '<img src="img/smileys2/2.gif" alt=":(" border="0" />',
    '<img src="img/smileys2/3.gif" alt=":P" border="0" />',
    '<img src="img/smileys2/4.gif" alt=":S" border="0" />',
    '<img src="img/smileys2/5.gif" alt=":O" border="0" />',
    '<img src="img/smileys2/6.gif" alt="=D>" border="0" />',
    '<img src="img/smileys2/7.gif" alt=">: D<" border="0" />',
    '<img src="img/smileys2/8.gif" alt=": D" border="0" />',
    '<img src="img/smileys2/9.gif" alt=":-*" border="0" />'
  );

  // replace the bbcode
  $str = preg_replace($bbcode_smiles, $html_tags, $str);

  return $str;
}

echo '<p class="showmore" style="border:none;"><span>'.bbcode($fetch['comment']).'</span></p><div style="clear:both"></div>';

echo '<em class="arrow"></em><img src="alerts/alert.gif" alt="" /><br /><br /><span style ="position:absolute;left:5px;bottom:5px">
<small><em>'.$fetch['created'].'</em></small></span></div>';
echo '<div style="clear:both"></div></div>';
	}
else
{ 
echo '';
} 



}
else
{
echo '';
}


}

visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: bbcode
CodenStuff
You should put your functions outside all other code..example dont put it inside an "IF" statement, try this:
Code: Select all
if(!empty($fetch['comment']))
{
   
  if($fetch['alerts']==0) {

echo '<div class="c_cont">';


echo '<p class="showmore" style="border:none;"><span>'.bbcode($fetch['comment']).'</span></p><div style="clear:both"></div>';

echo '<em class="arrow"></em><img src="alerts/alert.gif" alt="" /><br /><br /><span style ="position:absolute;left:5px;bottom:5px">
<small><em>'.$fetch['created'].'</em></small></span></div>';
echo '<div style="clear:both"></div></div>';
   }
else
{ 
echo '';
} 



}
else
{
echo '';
}

function bbcode($str) {
  // delete 'http://' because will be added when convert the code
  $str = str_replace('[url=http://', '[url=', $str);
  $str = str_replace('[url]http://', '[url]', $str);

  // Array with RegExp to recognize the code that must be converted
  $bbcode_smiles = array(
    // RegExp for [b]...[/b], [i]...[/i], [u]...[/u], [block]...[/block], [color=code]...[/color], [br]
    '/\[b\](.*?)\[\/b\]/is',
    '/\[i\](.*?)\[\/i\]/is',
    '/\[u\](.*?)\[\/u\]/is',
    '/\[block\](.*?)\[\/block\]/is',
    '/\[color=(.*?)\](.*?)\[\/color\]/is',
    '/\[br\]/is',

    // RegExp for [url=link_address]..link_name..[/url], or [url]..link_address..[/url]
    '/\[url\=(.*?)\](.*?)\[\/url\]/is',
    '/\[url\](.*?)\[\/url\]/is',

    // RegExp for [img=image_address]..image_title[/img], or [img]..image_address..[/img]
    '/\[img\=(.*?)\](.*?)\[\/img\]/is',
    '/\[img\](.*?)\[\/img\]/is',

    // RegExp for sets of characters for smiles: :), :(, :P, :P, ...
    '/:\)/i', '/:\(/i', '/:P/i', '/:S/i', '/:O/i', '/=D\>/i', '/\>:D\</i', '/:D/i', '/:-\*/i'
  );

  // Array with HTML that will replace the bbcode tags, defined inthe same order
  $html_tags = array(
    // <b>...</b>, <i>...</i>, <u>...</u>, <blockquote>...</blockquote>, <span>...</span>, <br/>
    '<b>$1</b>',
    '<i>$1</i>',
    '<u>$1</u>',
    '<blockquote>$1</blockquote>',
    '<span style="color:$1;">$2</span>',
    '<br/>',

    // a href...>...</a>, and <img />
    '<a target="_blank" href="http://$1">$2</a>',
    '<a target="_blank" href="http://$1">$1</a>',
    '<img src="$1" alt="$2" />',
    '<img src="$1" alt="$1" />',

    // The HTML to replace smiles. Here you must add the address of the images with smiles
    '<img src="img/smileys2/1.gif" alt=":)" border="0" />',
    '<img src="img/smileys2/2.gif" alt=":(" border="0" />',
    '<img src="img/smileys2/3.gif" alt=":P" border="0" />',
    '<img src="img/smileys2/4.gif" alt=":S" border="0" />',
    '<img src="img/smileys2/5.gif" alt=":O" border="0" />',
    '<img src="img/smileys2/6.gif" alt="=D>" border="0" />',
    '<img src="img/smileys2/7.gif" alt=">: D<" border="0" />',
    '<img src="img/smileys2/8.gif" alt=": D" border="0" />',
    '<img src="img/smileys2/9.gif" alt=":-*" border="0" />'
  );

  // replace the bbcode
  $str = preg_replace($bbcode_smiles, $html_tags, $str);

  return $str;
}
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: bbcode
Dummy1912
loove; loove; loove;

we love you #CodenStuff

i had to put it above the if

instead at the bottom because i got a error

so now it worked thanks :D
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
5 posts Page 1 of 1
Return to “Help & Support”