Nexy Posted June 9, 2008 Share Posted June 9, 2008 Why Hello There! I was wondering if it's possible with php, the way this forum uses emoticons. Where you click a smile and it turns into into text inside the textarea. Then when you hit submit it's the actual picture. If there is a way with php, can I get a guide on how to do it? Thank You! Quote Link to comment Share on other sites More sharing options...
keeB Posted June 9, 2008 Share Posted June 9, 2008 <?php $text = "Wow that is really cool! :X" //emoticon code $text = str_replace($text, "", '<img src="http://mysite.com/emote/tongue.gif">'); $text = str_replace($text, ":X", '<img src="http://mysite.com/emote/other.gif">'); echo $text; ?> Quote Link to comment Share on other sites More sharing options...
Nexy Posted June 9, 2008 Author Share Posted June 9, 2008 I tried that, and it changed all of the text to the smile. o.O Only the smile appears... $csql = "SELECT time, user, subject, content FROM comments WHERE newsid = '".$_GET['id']."'"; $cres = mysql_query($csql) OR die(mysql_error()); while($com = mysql_fetch_array($cres)) { $text = $com['content']; echo "<div class='margin' style='width: 500px; text-align: left; font-size: .7em'>"; echo "By: <span style='color: white'>" . $com['user'] . "</span> | "; echo "<span style='color: #A2B5CD'>" . $com['subject'] . "</span> @ "; echo "<span style='color: #ADD8E6'>" . $com['time'] . "</span><br /><img src='images/line.png' alt='' /><br />"; $text = str_replace($text, "", '<img src="board/images/smiles/happy.gif" alt="" />'); echo "<span style='color: #A2B5CD'>" . $text . '</span>'; echo "</div><br />"; } Quote Link to comment Share on other sites More sharing options...
Nexy Posted June 9, 2008 Author Share Posted June 9, 2008 I figured out why it was doing that, $text had to be at the end inside str_replace. Any way to make the smile a text inside the textarea when they click the image? Thank You! Quote Link to comment Share on other sites More sharing options...
keeB Posted June 9, 2008 Share Posted June 9, 2008 Use JavaScript. Quote Link to comment Share on other sites More sharing options...
Nexy Posted June 9, 2008 Author Share Posted June 9, 2008 Any link where I could learn how to do it in javascript, I must be googling the wrong thing. Quote Link to comment Share on other sites More sharing options...
aseaofflames Posted June 9, 2008 Share Posted June 9, 2008 i use this for my chatroom: <?php //find all images in smilies directory echo "<div id=\"smilies\">"; $i = 0; if ($handle = opendir('./smilies')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { //replace smilie file name with :filename: $show = str_replace('.gif','',$file); $show = ":".$show.":"; echo "<a onclick=\"AddItem('".$show."');\"><img src=\"smilies/".$file."\" alt=\"".$show."\"></a> \n"; //create new row every 15 smilies if($i==15) { $i=0; echo "<br>"; } $i++; } } closedir($handle); } } ?> javascript (add to head) <script type="text/javascript"> <!-- function AddItem(ItemId) { document.getElementById('message').value = document.getElementById('message').value + ItemId; document.getElementById('message').focus(); } --> this will take all smilies in the ./smilies directory output them with proper onclick events so that when they are clicked the coorisponding code will appear in the textbox 'message' convert back to images <?php function parse_smilies($text) { if ($handle = opendir('./smilies')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $s = str_replace('.gif','',$file); $show[] = ":".$s.":"; $image[] = "<img src='smilies/".$file."' alt='".$s."'>"; } } closedir($handle); } $text = str_replace($show,$image,$text); return $text; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.