runnerjp Posted May 16, 2008 Share Posted May 16, 2008 hey guys... ok im trying to display images in the message field..so for example if i user types it will show i happy face! here is my code <?php echo (emoticon($message)); function emoticon($msg) { $msg = str_replace("", "<IMG src=\".http://www.website.com/members/shoutbox/images/smile.gif\">", $msg); return $msg; }?> but for some reaosn it just displays still... am i doing it right? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 16, 2008 Share Posted May 16, 2008 It worked fine for me... <?php $message = "Hello "; echo emoticon($message); function emoticon($msg){ $msg = str_replace("", "<IMG src=\".http://www.website.com/members/shoutbox/images/smile.gif\">", $msg); return $msg; } ?> Quote Link to comment Share on other sites More sharing options...
soycharliente Posted May 16, 2008 Share Posted May 16, 2008 There is a period at the beginning of the URL. Maybe that is causing a problem. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 16, 2008 Author Share Posted May 16, 2008 humm ok imy script works fine by showin the image if the right "icon" is ented via <?php $message = "Hello "; echo emoticon($message); function emoticon($msg){ $msg = str_replace("", "<IMG src=\".http://www.website.com/members/shoutbox/images/smile.gif\">", $msg); return $msg; } ?> ... but when i try and do it via my script show below .... it does not do it... have i done something wrong?? <?php require ("required.php"); echo "<!-- $scriptname v$version Start -->\n\n"; echo "<HTML>\n"; echo " <HEAD>\n"; echo " <LINK rel=\"stylesheet\" type=\"text/css\" href=\"shoutbox/tagboard.css\">\n"; echo " </HEAD>\n"; echo " <BODY topmargin=\"2\" leftmargin=\"2\" bottommargin=\"2\" rightmargin=\"2\">\n"; $user2 = $_GET['username']; if ($usemysql == 1) { /* Load the tagboard, the X number of most recent posts */ if ($order == "0") $SQL = "SELECT * FROM $tablname WHERE account = '$user2' ORDER BY id DESC LIMIT 3"; $results = mysql_db_query($database, "$SQL", $connection); if (!$results) return ("ERROR: " . mysql_error() . "\n$SQL\n"); while ($row = mysql_fetch_array($results)) { $nick = $row["nick"]; $url = $row["url"]; $message = $row["message"]; $datetime = $row["datetime"]; /* Add Emoticons to the user's message */ if ($emoticon == 1) emoticon($message); /* Some people don't have web sites, so we check to see if they put a URL in the database */ if ($url=="" or $url=="http://") /* If they didn't then we just display the nick and the message */ $nick = "<B>$nick"; else /* If they did, then we link it!! */ $nick = "<B><a href=\"$url\" target=\"_blank\">$nick</a>"; if ($timestamping == 1) echo " $nick ($datetime)$spacer</B> $message<BR>\n"; else echo " $nick$spacer</B> $message<BR>\n"; } /* Like always, we close the connection to the database */ mysql_close($connection); } else { $i = 0; $file_lines = file($flatfile); foreach($file_lines as $line) { if ($i <= $howmany) { $delim = strpos($line, "%%"); $ts_delim = strpos($line, "@@"); $ip_delim = strpos($line, "##"); $nick = substr($line, 0, $delim); $message = substr($line, $delim + 2, $ts_delim - $delim - 2); $ts = substr($line, $ts_delim + 2, $ip_delim - $ts_delim - 2); if ($timestamping == 1) echo " <B>$nick ($ts)$spacer</B> "; else echo " <B>$nick$spacer</B> "; echo (emoticon($message)); echo "<BR>\n"; $i++; } } } function emoticon($msg) { $msg = str_replace("o:-)", "<IMG src=\"http://www..com/members/shoutbox/images/angel.gif\">", $msg); $msg = str_replace("o:)", "<IMG src=\"http://www..com/members/shoutbox/images/angel.gif\">", $msg); $msg = str_replace("O:-)", "<IMG src=\"http://www..com/members/shoutbox/images/angel.gif\">", $msg); $msg = str_replace("O:)", "<IMG src=\"http://www.r.com/members/shoutbox/images/angel.gif\">", $msg); $msg = str_replace(":-)", "<IMG src=\"http://www.com/members/shoutbox/images//smile.gif\">", $msg); $msg = str_replace("", "<IMG src=\"http://www..com/members/shoutbox/images/smile.gif\">", $msg); return $msg; } ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 16, 2008 Share Posted May 16, 2008 On this line if ($emoticon == 1) Where is the variable $emoticon coming from? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 16, 2008 Author Share Posted May 16, 2008 soory this is in my config file (easyer to edit it later on ) where i set it to this /* Enable emoticons */ $emoticon = 1; this is under require ("required.php");.. which is called... thanks fo looking tho Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 16, 2008 Share Posted May 16, 2008 I see what you did wrong. Here, you have two options: 1) Store the new $msg in a variable: /* Add Emoticons to the user's message */ if ($emoticon == 1) $msg = emoticon($message); 2) Pass the variable by reference in the function (advised, actually): function emoticon(&$msg){ $msg = str_replace("", "<IMG src=\".http://www.website.com/members/shoutbox/images/smile.gif\">", $msg); } Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 16, 2008 Author Share Posted May 16, 2008 haha this is pants lol i got rid of if ($emoticon == 1) $msg = emoticon($message); yet the emotion still does not show... very strange indeed Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 16, 2008 Share Posted May 16, 2008 No, you don't get what I said. You didn't have the variable assignment in the line. Copy and paste exactly what I typed on the first option where you had the other lines. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 16, 2008 Author Share Posted May 16, 2008 well i did it and no luck... i ill paste current code for you <? require ("required.php"); echo "<!-- $scriptname v$version Start -->\n\n"; echo "<HTML>\n"; echo " <HEAD>\n"; echo " <LINK rel=\"stylesheet\" type=\"text/css\" href=\"shoutbox/tagboard.css\">\n"; echo " </HEAD>\n"; echo " <BODY topmargin=\"2\" leftmargin=\"2\" bottommargin=\"2\" rightmargin=\"2\">\n"; $user2 = $_GET['username']; if ($usemysql == 1) { /* Load the tagboard, the X number of most recent posts */ if ($order == "0") $SQL = "SELECT * FROM $tablname WHERE account = '$user2' ORDER BY id DESC LIMIT 3"; $results = mysql_db_query($database, "$SQL", $connection); if (!$results) return ("ERROR: " . mysql_error() . "\n$SQL\n"); while ($row = mysql_fetch_array($results)) { $nick = $row["nick"]; $url = $row["url"]; $message = $row["message"]; $datetime = $row["datetime"]; /* Add Emoticons to the user's message */ if ($emoticon == 1) $msg = emoticon($message); /* Some people don't have web sites, so we check to see if they put a URL in the database */ if ($url=="" or $url=="http://") /* If they didn't then we just display the nick and the message */ $nick = "<B>$nick"; else /* If they did, then we link it!! */ $nick = "<B><a href=\"$url\" target=\"_blank\">$nick</a>"; if ($timestamping == 1) echo " $nick ($datetime)$spacer</B> $message<BR>\n"; else echo " $nick$spacer</B> $message<BR>\n"; } /* Like always, we close the connection to the database */ mysql_close($connection); } else { $i = 0; $file_lines = file($flatfile); foreach($file_lines as $line) { if ($i <= $howmany) { $delim = strpos($line, "%%"); $ts_delim = strpos($line, "@@"); $ip_delim = strpos($line, "##"); $nick = substr($line, 0, $delim); $message = substr($line, $delim + 2, $ts_delim - $delim - 2); $ts = substr($line, $ts_delim + 2, $ip_delim - $ts_delim - 2); if ($timestamping == 1) echo " <B>$nick ($ts)$spacer</B> "; else echo " <B>$nick$spacer</B> "; if ($emoticon == 1) echo (emoticon($message)); echo "<BR>\n"; $i++; } } } function emoticon($msg) { $msg = str_replace("o:-)", "<IMG src=\"http://www..com/members/shoutbox/images/angel.gif\">", $msg); $msg = str_replace("o:)", "<IMG src=\"http://www.com/members/shoutbox/images/angel.gif\">", $msg); $msg = str_replace("O:-)", "<IMG src=\"http://wwwcom/members/shoutbox/images/angel.gif\">", $msg); $msg = str_replace("O:)", "<IMG src=\"http://www.com/members/shoutbox/images/angel.gif\">", $msg); $msg = str_replace(":-)", "<IMG src=\"http://www.com/members/shoutbox/images//smile.gif\">", $msg); $msg = str_replace("", "<IMG src=\"http://www..com/members/shoutbox/images/smile.gif\">", $msg); return $msg; } ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 16, 2008 Share Posted May 16, 2008 echo " $nick$spacer</B> $message<BR>\n"; You're echoing $message, and not $msg. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 16, 2008 Author Share Posted May 16, 2008 ah yes didnt see that... ty topic solved 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.