Jump to content

[SOLVED] Pictures to Textarea


Nexy

Recommended Posts

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!  :)

Link to comment
Share on other sites

<?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;

?>

Link to comment
Share on other sites

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 />";

}

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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