Convert Texts to Smilies

Written by @m_k_amin 14 December 2012

If you want to make a forum, chat-room or similar scripts, you'll need to add some smilies effects. This code shows how to convert a code to a special smiley. Download the full package from the attachment and Enjoy!

Code Snippet:

                                                
                                                <!-- this script is provided by www.phpfreecode.com coded by: Kerixa Inc. -->
<!-- This Script is from www.hawkee.com, found at www.phpfreecode.com-->

<form action="" method="post">
	<table align="center" style="width: 359px; height: 81px;border: 2px  dashed #000066;">
		<tr>
			<td  style="background-color: #DDFFFF;width: 77px; text-align: center;">
			Text<br>&amp;<br>Smilies :</td>
			<td  style="background-color: #DDFFFF;width: 112px">
			<textarea name="text" style="width: 282px; height: 86px">
<?php 
if (!isset($_POST['Submit'])){
?>
Hi :-)
How are you? B-)
Are you sad? :-(
Are you surprised? :-O
Take it easy :-D
<?php } else echo $_POST['text'] ?>
</textarea></td>
		</tr>
		<tr style="text-align: center">
			<td  style="width: 77px">&nbsp;</td>
			<td style="width: 112px; text-align: left;">
		<input name="Submit" style="width: 133px; height: 29px;" type="submit" value="Convert"></td>
		</tr>
	</table>
</form>
<?php if (isset($_POST['Submit'])){ ?>
	<table align="center" style="width: 359px; height: 81px;border: 2px  dashed #000066;">
		<tr>
			<td  style="text-align: left;">
<?php
$sm = array(
        ':-)' => 'happy.jpg',
        ':-O' => 'suprise.jpg',
        ':-(' => 'sad.jpg',
        ':-D' => 'grin.jpg',
        'B-)' => 'grin.jpg'
    );
    $text=$_POST['text'];
    foreach($sm as $smiley => $img){
        $text = str_replace($smiley, "<img src='smilies/$img' />", $text);
    }
	echo "<pre>$text</pre>";
?>
			</td>
		</tr>
		</table>
<?php } ?>
<div style="text-align: center">
	<br>
	<font face="Tahoma"><span style="font-size: 8pt; text-decoration: none"><a target="_blank" href="http://www.phpfreecode.com/">PHP Free Code</a></span></font></div>
<a target='_blank' href='www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>                                                
                                            

Example:


About @m_k_amin

This user is pending a biography.

M
TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: Manaakividuinfo.com, karticksv, sava, tinatina, sandiegostrippersinsandiego
advertisement 2