Jump to content


Photo

smilies in php message board


  • Please log in to reply
9 replies to this topic

#1 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 20 October 2006 - 04:09 PM

i have made my own message board, but i want to add smilies. just ones which when you put a colon and a bracket that it recognises it as an image....how would i do this???
Visit my Game - Under Construction

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 October 2006 - 06:51 PM

Search google or whatever foir emoticon tutorial or search this forum. There has been posts like yours a few times.

However this tutorial should get you going.

#3 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 21 October 2006 - 08:25 AM

thanks ill take a look :)
Visit my Game - Under Construction

#4 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 21 October 2006 - 09:31 AM

i get an error...but i dont understand :(
Parse error: syntax error, unexpected '[', expecting ')' in /home/lordofth/public_html/forum/viewthread.php on line 78

<?
    function emoticon($r['post']) {
  // the line below this is line 78
  $emoticonarray = array(
    ':)'  => 'smile.gif',
    ':('  => 'sad.gif',
    ';)'  => 'wink.gif',
    ':P'  => 'tongue.gif'
  );
    foreach($emoticonarray as $emoticon => $img) {
    $search[] = $emoticon;
    $replace[] = '<img src="/emoticons/' . $img . '" alt="' . $emoticon . '" />';
  }
  $r['post'] = str_replace($search, $replace, $r['post']);
  return $r['post'];
}

    echo stripslashes($r['username']); ?></td>
    <td style="width:80%;background-color:#101010;">
    <? 
    echo nl2br(stripslashes($r['post'])); ?></td>
  </tr>
</table>

Visit my Game - Under Construction

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 October 2006 - 11:48 AM

Its actually to do with this:
function emoticon($r['post']) {


You cannot use an array as parameter for tghe function, you can passa n array to the function when you call it. So remove the $r['post'] variable and replace it with $r_post or something similiar. Also make sure chnage any other instances of $r['post'] too in the emoticon function to $r_post too.

Then when you call the emotion function you can use $r['post']:
// call the emoticon function
$r['post'] = emoticon($r['post']);


#6 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 22 October 2006 - 06:57 PM

didn't really understand that :(

could you rewrite this? then in future i will understand :)
   function emoticon($r['post']) {
  // defines the emoticons
  $emoticonarray = array(
    ':)'  => 'smile.gif',
    ':('  => 'sad.gif',
    ';)'  => 'wink.gif',
    ':P'  => 'tongue.gif',
    ':'('  => 'cry.gif'
  );
   foreach($emoticonarray as $emoticon => $img) {
    $search[] = $emoticon;
    $replace[] = '<img src="images/emotions/' . $img . '" alt="' . $emoticon . '" />';
  }
   $r['post'] = str_replace($search, $replace, $r['post']);

  return $r['post'];
}

    echo stripslashes($r['username']); ?>

Visit my Game - Under Construction

#7 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 22 October 2006 - 07:26 PM

anyone? if you don't want to rewrite then can you then explain in simple terms what wildteen88 said???
Visit my Game - Under Construction

#8 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 22 October 2006 - 09:12 PM

sorry to post again but nobody replied :(
Visit my Game - Under Construction

#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 October 2006 - 05:19 PM

You need to read up on creating your own functions if you are not understanding the code. Prehaps reading this may help yuou understand.

if you follow what I said IN my previous post your function should work. However the following is what your code should be:
// we difine our function here
// PHP will not run this function until we tell it to
// $post is the paramter for the function.
function emoticon($post)
{
    // defines the emoticons
    $emoticonarray = array( ':)'  => 'smile.gif',
                            ':('  => 'sad.gif',
                            ';)'  => 'wink.gif',
                            ':P'  => 'tongue.gif',
                            ':('  => 'cry.gif'
                           );

    foreach($emoticonarray as $emoticon => $img)
    {
        $search[] = $emoticon;
        $replace[] = '<img src="images/emotions/' . $img . '" alt="' . $emoticon . '" />';
    }

    $post = str_replace($search, $replace, $post);

    return $post;
}

// We'll now tell PHP to run our emoticon function we defined above:
// we'll pass $r['post'] as a paramter to the emoticon function.
// The function will now converet any smilie symbols in to images
$r['post'] = emoticon($r['post']);


#10 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 23 October 2006 - 05:29 PM

This has been answered now in another post!

The user obviously double posted, I didn't see this one :(

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users