Jump to content

[SOLVED] Pictures to Textarea


Nexy

Recommended Posts

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

}

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

Archived

This topic is now archived and is closed to further replies.

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