Hi, been away from coding for pretty long and trying to get back into coding with rusty skill so bear with me. I have a simple blog but what I would like to do is for the output to show smileys and BBCode when it show the output.
Here is the code from tutorial:
<?php
// function to convert bbcode, and smiles to html
function bbcodeHtml($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="icos/1.gif" alt=":)" border="0" />',
'<img src="icos/2.gif" alt=":(" border="0" />',
'<img src="icos/3.gif" alt=":P" border="0" />',
'<img src="icos/4.gif" alt=":S" border="0" />',
'<img src="icos/5.gif" alt=":O" border="0" />',
'<img src="icos/6.gif" alt="=D>" border="0" />',
'<img src="icos/7.gif" alt=">: D<" border="0" />',
'<img src="icos/8.gif" alt=": D" border="0" />',
'<img src="icos/9.gif" alt=":-*" border="0" />'
);
// replace the bbcode
$str = preg_replace($bbcode_smiles, $html_tags, $str);
return $str;
}
// Test
$str = 'Test [b]PHP tutorials[/b].[br]
[i][color=blue]Blue, and oblique string[/color][/i], underlined: [u]BBCODE tags[/u][br]
Link: [url=http://coursesweb.net/php-mysql/]PHP Course[/url], smiles: =D>, :), >:D< ...
[block]Text added in "block", for blockquote[/block]
An image: [img=http://coursesweb.net/imgs/webcourses.gif]Course Web[/img]';
echo bbcodeHtml($str);
?>
Here is my output blogging code:
<?
$getnews = mysql_query("select * from news ORDER BY id DESC LIMIT $from, $index_postnumber");
while($r=mysql_fetch_array($getnews)){
extract($r);
$news=nl2br($news);
echo("<table width=98% align=center cellspacing=5 cellpadding=0 border=0 class=newsborder2>
<tr class=newstitlebg>
<td> <span class=newstitleheader>$title</span></td>
</tr>
<tr>
<td> <span class=newsdate>$date</span></td>
</tr>
<tr>
<td><span class=newstext>$news</span><p></td>
</tr>
</table><br>");
}
?>
I've tried to insert smileys/BBCode inside my code in few different ways and doesn't have good results. I would appreciate your help in this and that should do it for me, hopefully! 😃 Thanks!