RTS Posted October 12, 2006 Share Posted October 12, 2006 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? Link to comment https://forums.phpfreaks.com/topic/23728-how-to-make-smilies-work/ Share on other sites More sharing options...
Daniel0 Posted October 12, 2006 Share Posted October 12, 2006 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] Link to comment https://forums.phpfreaks.com/topic/23728-how-to-make-smilies-work/#findComment-107765 Share on other sites More sharing options...
RTS Posted October 12, 2006 Author Share Posted October 12, 2006 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 scriptread.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] Link to comment https://forums.phpfreaks.com/topic/23728-how-to-make-smilies-work/#findComment-107962 Share on other sites More sharing options...
wildteen88 Posted October 12, 2006 Share Posted October 12, 2006 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] Link to comment https://forums.phpfreaks.com/topic/23728-how-to-make-smilies-work/#findComment-107973 Share on other sites More sharing options...
RTS Posted October 12, 2006 Author Share Posted October 12, 2006 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]<?phpsession_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] Link to comment https://forums.phpfreaks.com/topic/23728-how-to-make-smilies-work/#findComment-108003 Share on other sites More sharing options...
RTS Posted October 12, 2006 Author Share Posted October 12, 2006 anyone? im still somewhat new to php, so this kind of thing is hard for me. Link to comment https://forums.phpfreaks.com/topic/23728-how-to-make-smilies-work/#findComment-108128 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.