SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2002
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A little help with my Shoutbox Smilie Replacement

    ok, i'm not sure what i'm doing wrong, so someone please help me here. the smilies are stored in a array ($ascii_emotions) and the emoticon names are stored in a array also ($graphic_emotions). what i'm trying to do here is use the for() command to cycle thru all these ascii and graphic emotion arrays, and replace them with each other. here's my code:
    PHP Code:
    function replace_smilies($message) {
    $ascii_emotions = array(":)"":("":D"":p"":o"":|"";)"">:("":eek:"":confused:"":dies:"":rolleyes:"":cool:"":cries:"":mad"":shyness:"":zzz:"":uhoh:"":#$!!:");
    $graphic_emotions = array("smile""sad""briggin""razz""embarassed""none""wink""mad""eek""confused""dead""rolleyes""cool""cry""mad""shy""sleep""uhoh""upset");

    $counted count($ascii_emotions);
    for (
    $ii=0$ii<=$counted$ii++) {

        
    $message str_replace($ascii_emotions[$ii], "<img src=\"./../images/smilies/blue/smilie_$graphic_emotions[$ii].gif\" alt=\"\" align=\"absmiddle\""$message);

        return;
    }    

    }
    $qry mysql_query('SELECT * FROM SHOUTBOX ORDER BY SHOUT_ID DESC LIMIT 9');
    while (
    $rtn mysql_fetch_array($qry)) {
    replace_smilies($rtn[SHOUT_MESSAGE]);
    $date date('M dS, Y \a\t h:g A'$rtn[SHOUT_DATE]);
        echo 
    "
        <tr><td class=\"tablestyle
    $switch[$i]\">
            "
    ;
            if (
    $rtn[SHOUT_ADD] == "") {
                echo 
    "<b>$rtn[SHOUT_NAME]</b>:<br>";
            } else {
                echo 
    "<a href=\"$rtn[SHOUT_ADD]\" alt=\"$date :: IP Logged\">$rtn[SHOUT_NAME]</a>:<br>";
            }
        echo 
    "
         
    $message</td></tr>
        "
    ;
        
    $i = !$i;
    }
    $i = !$i
    InQuE

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What error are you getting?

    Note: if the variable is a valid array then the count( ) function returns the actual number of elements, starting with a value of 1. (e.g. an array with one element - $arr[0] = "blah" - will return a count of 1). Therefore ...
    PHP Code:
    $counted count($ascii_emotions) - 1
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Guru enygmadae's Avatar
    Join Date
    Sep 2002
    Location
    Dallas, Tx.
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    um..FYI, str_replace takes in arrays too....

    PHP Code:
    $array1=array(":)",":(");
    $array2=array("smile","sad");

    $text="this is just a smile kind of day. I hope you're not sad.";
    $text=str_replace($array2,$array1,$text);
    echo 
    "New text: ".$text
    try something like that....
    PHP News, Views and Community: http://www.phpdeveloper.org


Bookmarks

Posting Permissions

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