Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem replacing smilies

    hello, i have a really simple code for replacing a string message containing smilies symbols for smilies images. heres my code:

    PHP Code:
    <?php
    include("../connect.php");

    $messagein"smilies: =) =D =( (!)";

    $smilies=mysql_query("SELECT * FROM smilies")or die(mysql_error());

    while (
    $get=mysql_fetch_array($smilies))
        {
        
    $symbol=$get['symbol'];
        
    $smilie=$get['url'];    
        
    $img="<img src='../shoutbox/smilies/".$smilie."' border='0' width='15' height='15'>";
        
    $message=str_replace($symbol$img$messagein);
        }
    echo 
    $message;
    ?>
    as it its, with the echo outside the while loop, it will only replace one smilie, the last in the mysql smilies table.
    for obvious reasons, if i put the echo inside the while loop, it will repeat the message as many times as how many smilies i have in the mysql smilies table, what i dont want, i just want the message to show once, replacing all the smilies. how to do that?!

    here's a list of my available smilies http://fael097.site11.com/test/test6.php
    and here's my code i posted above, as its (not)working right now http://fael097.site11.com/test/test5.php

    thank you in advance

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    There are some PHP emoticon classes you can use.
    I also found this:
    http://www.webcodez.net/php-mysql/php-smilies-system/

    Maybe you want to program your own, but if there's already scripts available ...

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    E.g. you could store patterns and replacements in arrays and then use these arrays in str_replace() after the while loop. Something like this:
    PHP Code:
    <?php
    include("../connect.php");

    $messagein"smilies: =) =D =( (!)";

    $smilies=mysql_query("SELECT * FROM smilies")or die(mysql_error());

    $symbol = array();
    $img = array();
    while (
    $get=mysql_fetch_array($smilies))
    {
     
    $symbol[]=$get['symbol'];
     
    $smilie=$get['url'];
     
    $img[]="<img src='../shoutbox/smilies/".$smilie."' border='0' width='15' height='15'>";
    }
    $message=str_replace($symbol$img$messagein);
    echo 
    $message;
    ?>

  • Users who have thanked SKDevelopment for this post:

    fael097 (03-22-2010)

  • #4
    New Coder
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks a lot bud, thats exactly what i was looking for.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •