Jump to content

smilies in php message board


almightyegg

Recommended Posts

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

However [url=http://ryanslife.net/2006/07/12/php-simple-emoticon-support/]this tutorial[/url] should get you going.
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

[code]<?
    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>[/code]
Its actually to do with this:
[code=php:0]function emoticon($r['post']) {[/code]


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']:
[code=php:0]// call the emoticon function
$r['post'] = emoticon($r['post']);[/code]
didn't really understand that :(

could you rewrite this? then in future i will understand :)
[code]  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']); ?>[/code]
You need to read up on creating your own functions if you are not understanding the code. Prehaps reading [url=http://dev.fyicenter.com/faq/php/php_function_definition.php]this[/url] 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:
[code]// 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']);[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.