SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Emoticons

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Emoticons

    is there a wey to make an admin-type page where you can update a php file for emoticons?
    let me explain what i want. i have a php file that i include in a document and it turns :) into graphical ones and such. what i want is to be able to use an admin page to add more smilies to that file. while NOT using MYSql. I know some messageboards have this. they have a place for the path to the graphic and a place for the code to the smilie. can it be done heres my emoticon.php file:

    PHP Code:

    <?
    function Do_faces ($article) {
    $article nl2br($article);
    $article str_replace(":)","<img src=\"/images/smiles/smile.gif\" border=\"0\" alt=\"\">",$article);
    $article str_replace(":(","<img src=\"/images/smiles/frown.gif\" border=\"0\" alt=\"\">",$article);
    $article str_replace(":p","<img src=\"/images/smiles/tongue.gif\" border=\"0\" alt=\"\">",$article);
    $article str_replace(":o","<img src=\"/images/smiles/redface.gif\" border=\"0\" alt=\"\">",$article);
    $article str_replace(":D","<img src=\"/images/smiles/biggrin.gif\" border=\"0\" alt=\"\">",$article);
    $article str_replace(";)","<img src=\"/images/smiles/wink.gif\" border=\"0\" alt=\"\">",$article);
    return 
    $article;
    }
    ?>

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay so your first issue, I would store the smilies and their graphic name in a text file, then I would read the text file in and use str_replace() array support to knock them all out in one swoop. This way you can smilies to the text file and never have to touch the function.
    The text file
    Code:
    :)||smile.gif
    :(||frown.gif
    :p||tongue.gif
    :o||redface.gif
    :D||biggrin.gif
    ;)||wink.gif

    The PHP function to transform the smilies into graphics.
    PHP Code:
    function DoFaces($article) {
        
    $data file("smilies.txt");
        foreach(
    $data as $key => $val) {
            
    $tmp explode("||"$val);
            
    $faces[] = $tmp[0];
            
    $pics[] = '<img src="/images/smiles/'.$tmp[1].'" border="0" alt="">';
            }
        
    $article nl2br($article);
        
    $article str_replace($faces$pics$article);    
        return 
    $article;
        }


    $article DoFaces($article); 



    Now an admin tool should be fairly easy to make all you need to do is use PHP's filesystem functions to open the file and write to it or simply add to it manually.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks... i can figure out how to make an admin... :P


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
  •