Jump to content

[SOLVED] script to show images in my message :P


runnerjp

Recommended Posts

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?

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

?>

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

?>

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

}

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

?>

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.