making small shoutbox

  • eagle
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Aug 22, 2004
  • Posts: 171
  • Status: Offline

Post March 15th, 2005, 4:53 am

i made a small shoutbox kinda thing now i want it to have emoticons

i was thingking of letting the users type stuff like

$smile

and make the php replace that $smile with <img src="smile.gif">

i have 2 files one witht he form and a nother that writes to a txt file

i tried to put this in the one that writes to txt file

$smile = <img src="smile.gif"> this dont work

anybody know whats wrong?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 15th, 2005, 4:53 am

  • Murdz
  • Novice
  • Novice
  • User avatar
  • Joined: Feb 03, 2005
  • Posts: 34
  • Status: Offline

Post March 15th, 2005, 5:14 am

... I don't understand why you are using a text file?

and why not use a simple:
PHP Code: [ Download ] [ Select ]
 
str_replace($smile,'<img src="images/smile.gif" alt="smile" />',$var_shoutout);
  1.  
  2. str_replace($smile,'<img src="images/smile.gif" alt="smile" />',$var_shoutout);
  • eagle
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Aug 22, 2004
  • Posts: 171
  • Status: Offline

Post March 15th, 2005, 5:22 am

thanx i'll test this later i dont have time atm i'll post if its what i needed

i like txt file

its easy to format :)
  • eagle
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Aug 22, 2004
  • Posts: 171
  • Status: Offline

Post March 15th, 2005, 5:28 am

sorry for double posting i just tried to test it but where should i put this?

if i should put this in the php that writes the comment to a txt file then it doesn't work
  • Hacker007
  • Proficient
  • Proficient
  • User avatar
  • Joined: Apr 07, 2004
  • Posts: 366
  • Loc: Riverside, CA
  • Status: Offline

Post March 15th, 2005, 8:28 pm

Post your Shout Box's Code, and we can tell you where to add the code for emoticons.

PHP Code: [ Download ] [ Select ]
str_replace($smile,'<img src="images/smile.gif" alt="smile" />',$var_shoutout);


That code will probably give you an error, or at least now work right, because it will think $smile is a variable, you should make it like :smile: or :)
http://www.koolzone.net
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post March 16th, 2005, 2:54 am

There is also an area in the Admin Area of your shoutbox in ShoutMix, that allows you to do this. It can replace, change, edit, and create your own smileys!
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • Murdz
  • Novice
  • Novice
  • User avatar
  • Joined: Feb 03, 2005
  • Posts: 34
  • Status: Offline

Post March 16th, 2005, 5:44 am

Yeah it works fine as a var except when you have similar smily values, eg:

Code: [ Download ] [ Select ]
:??:
and
Code: [ Download ] [ Select ]
:?
it won't distinguish between

but aside from hand typing all the values and checking for them, there has to be an easier way?
  • eagle
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Aug 22, 2004
  • Posts: 171
  • Status: Offline

Post March 16th, 2005, 10:16 am

OK i actualy got it done
a friend of mine helped me
now can anybody tell me the script where you can click on an image and some text gets added in the messagebox?
  • Hacker007
  • Proficient
  • Proficient
  • User avatar
  • Joined: Apr 07, 2004
  • Posts: 366
  • Loc: Riverside, CA
  • Status: Offline

Post March 16th, 2005, 11:10 am

You'll need Javascript. Something like

Code: [ Download ] [ Select ]
<html>
<head>
    <script language="javascript" type="text/javascript">
    function add_smile(smile){
             before = document.myform.message.value;
             after = before + " " + smile;
             document.myform.message.value = after;
    }
    </script>
</head>

<body>
<a href="javascript: add_smile(':)');"><img src="happy.gif"></a>
<a href="javascript: add_smile(':(');"><img src="sad.gif"></a>
<a href="javascript: add_smile(':|');"><img src="plain.gif"></a>
<form name="myform">
<textarea name="message"></textarea>
</form>

</body>
</html>
  1. <html>
  2. <head>
  3.     <script language="javascript" type="text/javascript">
  4.     function add_smile(smile){
  5.              before = document.myform.message.value;
  6.              after = before + " " + smile;
  7.              document.myform.message.value = after;
  8.     }
  9.     </script>
  10. </head>
  11. <body>
  12. <a href="javascript: add_smile(':)');"><img src="happy.gif"></a>
  13. <a href="javascript: add_smile(':(');"><img src="sad.gif"></a>
  14. <a href="javascript: add_smile(':|');"><img src="plain.gif"></a>
  15. <form name="myform">
  16. <textarea name="message"></textarea>
  17. </form>
  18. </body>
  19. </html>
http://www.koolzone.net
  • eagle
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Aug 22, 2004
  • Posts: 171
  • Status: Offline

Post March 16th, 2005, 2:21 pm

OK everything is running perfect

only one thing

when you use enter key, lets say i type

hello [enter]

wassup

this text will apear

wassup

hello


do you see the probleme?

Post March 16th, 2005, 3:52 pm

is it submiting to the db when you press enter

or is just going to a different line like now

hi
  • Hacker007
  • Proficient
  • Proficient
  • User avatar
  • Joined: Apr 07, 2004
  • Posts: 366
  • Loc: Riverside, CA
  • Status: Offline

Post March 16th, 2005, 4:48 pm

I'm not sure of that problem, let us see your code. If this is your code, from that other topic:

PHP Code: [ Download ] [ Select ]
<?php
 
 
 
 $data = file('profile.txt'); //Asigning the variable "$data" to our textfile
 
 $data = array_reverse($data); //Reversing all the data in the textfle
 
 if($data == "") //If the textfile has no data in it
 
  {
 
   print "<center>There is currently no comments. Please feel free to add your own</center>"; //Since there are no comments, display this default message
 
  }
 
 else //Else read from the text file and display it's contents
 
  {
 
 foreach($data as $element)
 
  {
 
   $element = trim($element);
 
   $peices = explode("|", $element);
 
   echo $peices[2] . $peices[1] . "" . $peices[0] . "";
 
  }
 
  }
 
?>
  1. <?php
  2.  
  3.  
  4.  
  5.  $data = file('profile.txt'); //Asigning the variable "$data" to our textfile
  6.  
  7.  $data = array_reverse($data); //Reversing all the data in the textfle
  8.  
  9.  if($data == "") //If the textfile has no data in it
  10.  
  11.   {
  12.  
  13.    print "<center>There is currently no comments. Please feel free to add your own</center>"; //Since there are no comments, display this default message
  14.  
  15.   }
  16.  
  17.  else //Else read from the text file and display it's contents
  18.  
  19.   {
  20.  
  21.  foreach($data as $element)
  22.  
  23.   {
  24.  
  25.    $element = trim($element);
  26.  
  27.    $peices = explode("|", $element);
  28.  
  29.    echo $peices[2] . $peices[1] . "" . $peices[0] . "";
  30.  
  31.   }
  32.  
  33.   }
  34.  
  35. ?>


I think it might have something to do with using file('profile.txt')... because it might make a line break show as 2 different things, then you reverse them, so it would put them in the wrong order.
http://www.koolzone.net
  • eagle
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Aug 22, 2004
  • Posts: 171
  • Status: Offline

Post March 17th, 2005, 5:14 am

here's my code
PHP Code: [ Download ] [ Select ]
<?php print ("<p>Information added, thank you</p> Please wait while we take you back\n");
 
$date = gmdate("M d Y", mktime(now));
 
$Trans = array(":)" => "<img src='smilies/smile.gif'>", ":alien:" => "<img src='smilies/alien.gif'>", ":clap:" => "<img src='smilies/clap.gif'>", ":guitar:" => "<img src='smilies/guitar.gif'>", ":D" => "<img src='smilies/biggrin.gif'>", ":blackeye:" => "<img src='smilies/blackeye.gif'>", ":blink:" => "<img src='smilies/blink.gif'>", ":dry:" => "<img src='smilies/dry.gif'>", ":idea:" => "<img src='smilies/idea.gif'>", ":haha:" => "<img src='smilies/laugh.gif'>", ":mad:" => "<img src='smilies/mad.gif'>", ":no:" => "<img src='smilies/no.gif'>", ":rofl:" => "<img src='smilies/rofl.gif'>", ":(" => "<img src='smilies/sad.gif'>", ":sleep:" => "<img src='smilies/sleep.gif'>", ":p" => "<img src='smilies/tong.gif'>"); //This swaps from image to text
 
 
 
$message = strtr($quote, $Trans); //This reads from the $quote variable and then applies the rules of your $Trans variable
 
 
 
$filename = "quotes.txt";
 
$fp = fopen ($filename, "a+");
 
fwrite ($fp, "  <br>
 
<!--QuoteEnd--></div><!--QuoteEEnd-->
 
 </div>
 
 $message
 
 <div>
 
 <!--QuoteEBegin-->
 
 <div class='quotemain'>
 
 <div class='quotetop'>QUOTE $name @ $date</div>");
 
fclose ($fp);
 
?>
  1. <?php print ("<p>Information added, thank you</p> Please wait while we take you back\n");
  2.  
  3. $date = gmdate("M d Y", mktime(now));
  4.  
  5. $Trans = array(":)" => "<img src='smilies/smile.gif'>", ":alien:" => "<img src='smilies/alien.gif'>", ":clap:" => "<img src='smilies/clap.gif'>", ":guitar:" => "<img src='smilies/guitar.gif'>", ":D" => "<img src='smilies/biggrin.gif'>", ":blackeye:" => "<img src='smilies/blackeye.gif'>", ":blink:" => "<img src='smilies/blink.gif'>", ":dry:" => "<img src='smilies/dry.gif'>", ":idea:" => "<img src='smilies/idea.gif'>", ":haha:" => "<img src='smilies/laugh.gif'>", ":mad:" => "<img src='smilies/mad.gif'>", ":no:" => "<img src='smilies/no.gif'>", ":rofl:" => "<img src='smilies/rofl.gif'>", ":(" => "<img src='smilies/sad.gif'>", ":sleep:" => "<img src='smilies/sleep.gif'>", ":p" => "<img src='smilies/tong.gif'>"); //This swaps from image to text
  6.  
  7.  
  8.  
  9. $message = strtr($quote, $Trans); //This reads from the $quote variable and then applies the rules of your $Trans variable
  10.  
  11.  
  12.  
  13. $filename = "quotes.txt";
  14.  
  15. $fp = fopen ($filename, "a+");
  16.  
  17. fwrite ($fp, "  <br>
  18.  
  19. <!--QuoteEnd--></div><!--QuoteEEnd-->
  20.  
  21.  </div>
  22.  
  23.  $message
  24.  
  25.  <div>
  26.  
  27.  <!--QuoteEBegin-->
  28.  
  29.  <div class='quotemain'>
  30.  
  31.  <div class='quotetop'>QUOTE $name @ $date</div>");
  32.  
  33. fclose ($fp);
  34.  
  35. ?>




Form:::
PHP Code: [ Download ] [ Select ]
<?php
 
 
 
 $data = file('quotes.txt'); //Asigning the variable "$data" to our textfile
 
 $data = array_reverse($data); //Reversing all the data in the textfle
 
 if($data == "") //If the textfile has no data in it
 
  {
 
   print "<center>There is currently no comments. Please feel free to add your own</center>"; //Since there are no comments, display this default message
 
  }
 
 else //Else read from the text file and display it's contents
 
  {
 
 foreach($data as $element)
 
  {
 
   $element = trim($element);
 
   $peices = explode("|", $element);
 
   echo $peices[2] . $peices[1] . "" . $peices[0] . "";
 
  }
 
  }
 
?>
 
</p>
  1. <?php
  2.  
  3.  
  4.  
  5.  $data = file('quotes.txt'); //Asigning the variable "$data" to our textfile
  6.  
  7.  $data = array_reverse($data); //Reversing all the data in the textfle
  8.  
  9.  if($data == "") //If the textfile has no data in it
  10.  
  11.   {
  12.  
  13.    print "<center>There is currently no comments. Please feel free to add your own</center>"; //Since there are no comments, display this default message
  14.  
  15.   }
  16.  
  17.  else //Else read from the text file and display it's contents
  18.  
  19.   {
  20.  
  21.  foreach($data as $element)
  22.  
  23.   {
  24.  
  25.    $element = trim($element);
  26.  
  27.    $peices = explode("|", $element);
  28.  
  29.    echo $peices[2] . $peices[1] . "" . $peices[0] . "";
  30.  
  31.   }
  32.  
  33.   }
  34.  
  35. ?>
  36.  
  37. </p>
  • Hacker007
  • Proficient
  • Proficient
  • User avatar
  • Joined: Apr 07, 2004
  • Posts: 366
  • Loc: Riverside, CA
  • Status: Offline

Post March 17th, 2005, 10:58 pm

Well, that isn't all of it, is it? I see never saw you declare $name/$quote to anything... and I don't see why you're exploding a pipe ("|").. Are you even writting a pipe into the quotes.txt?

From what i see, you're just writtting the HTML straight to the file.. And that Makes me wonder what is the point of even using explode() at all? Also, I wonder why you write the closing tags for the previous quotes first.. That can't be right, because then your first entry would have closing divs, to div that isn't there!

Sorry, I just don't know where to help on this one. I can post you an example of a shout box I made, and maybe that will help you see what functions do what...
http://www.koolzone.net
  • eagle
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Aug 22, 2004
  • Posts: 171
  • Status: Offline

Post March 18th, 2005, 5:42 am

You are right and name and quote are text boxes
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 18th, 2005, 5:42 am

Post Information

  • Total Posts in this topic: 19 posts
  • Users browsing this forum: No registered users and 356 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.