Jump to content

Archived

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

RTS

How to Make Smilies Work

Recommended Posts

i just downloaded a pack of snmilies for messages on my site, and i was wondering, how do i make it so that when someone types : ) it will come up as a smiley?

Share this post


Link to post
Share on other sites
Put them in an array like this then replace them:

[code]$smilies = array( // code => image
':)' => 'smile.gif',
':D' => "smile2.gif',
':(' => 'sad.gif',
);

$codes = array_keys($smilies);

$the_text = str_replace($codes,$smilies,$the_text);[/code]

Share this post


Link to post
Share on other sites
not quite sure how to put that in my code, but atleast I tried. it gave me [code]Parse error: parse error in /Library/WebServer/Documents/read.php on line 7[/code]

Heres my script
read.php
[quote]<?php
$con = mysql_connect("localhost","ZackBabtkis","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM messages WHERE ID=".$_GET['id']);
while($row = mysql_fetch_array($result))
  {
$the_text = echo "<table border=10 width=400 cellpadding=0 cellspacing=3><tr><td background=table.jpg><h1 align=center>Message:</h1>" . $row['Message'];
$smilies = array( // code => image
':)' => '<img src=smilies/smile.gif>',
);

$codes = array_keys($smilies);

$the_text = str_replace($codes,$smilies,$the_text);

  }
echo "</td></tr></table>";

mysql_close($con);
?>[/quote]

Share this post


Link to post
Share on other sites
You had a few badf syntax errors. Using echo within  variable is not allowed and thus why you got the parse error. I have corrected this issue and tidy'd up your code a little too:
[code]<?php

$con = mysql_connect("localhost","ZackBabtkis","") or die('Could not connect: ' . mysql_error());
mysql_select_db("test", $con);

$result = mysql_query("SELECT * FROM messages WHERE ID=" . $_GET['id']);

while($row = mysql_fetch_array($result))
{
    $the_text = '<table border="10" width="400" cellpadding="0" cellspacing="3">
    <tr>
        <td background="table.jpg">
            <h1 align="center">Message:</h1>' . $row['Message'];

    $smilies = array( // code => image
        'Smiley' => '<img src=smilies/smile.gif>',
    );

    $codes = array_keys($smilies);

    $the_text = str_replace($codes,$smilies,$the_text);

    echo $the_text;
}

echo "      </td>
    </tr>
</table>";

mysql_close($con);

?>[/code]

Share this post


Link to post
Share on other sites
hmmmm, that didnt give me an error, but just showd up as the text ": )" do I need to have it in the message being sent? how would I put it in this code?
send.php:
[code]<?php
session_start();
$con = mysql_connect("localhost","ZackBabtkis","");
$subject = mysql_real_escape_string($_POST[subject]);
$message = mysql_real_escape_string($_POST[message]);
$user = $_COOKIE["user"];
$sender = $_SESSION['username'];
$date = date("F j, Y, g:i a");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("test", $con);
$sql = "INSERT INTO messages (Username, Sender, Subject, Message, Date) VALUES ('$user','$sender','$subject','$message', '$date')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Your message has been sent to $user";
mysql_close($con)
?>[/code]

Share this post


Link to post
Share on other sites
anyone? im still somewhat new to php, so this kind of thing is hard for me.

Share this post


Link to post
Share on other sites

×

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.