Jump to content

Recommended Posts

i know there is something iffy with the function :(

[code]<?
    function emoticon($r['post']) {
  $emoticonarray = array(
    ':)'  => 'smile.gif',
    ':('  => 'sad.gif',
    ';)'  => 'wink.gif',
    ':P'  => 'tongue.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']); ?></td>
    <td style="width:80%;background-color:#101010;">
    <?
    echo nl2br(stripslashes($r['post'])); ?></td>[/code]
Link to comment
https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/
Share on other sites

all i know is that it won't recognise the function...and it says:
Parse error: syntax error, unexpected '[', expecting ')' in /home/lordofth/public_html/forum/viewthread.php on line 76

line 76 is:    function emoticon($r['post']) {
Your getting confused between defining a function and calling one...

Try this:

[code]<?php
function emoticon($post) { //This defines the function
  $emoticonarray = array(
      ':)'  => 'smile.gif',
      ':('  => 'sad.gif',
      ';)'  => 'wink.gif',
      ':P'  => 'tongue.gif'
  );

  foreach($emoticonarray as $emoticon => $img) {
      $search[] = $emoticon;
      $replace[] = '<img src="images/emotions/' . $img . '" alt="' . $emoticon . '" />';
  }
  $post = str_replace($search, $replace, $post);
  return $post;
} // This is the end of the function

echo stripslashes($r['username']);
?>
</td>
<td style="width:80%;background-color:#101010;">
<?php
echo nl2br(stripslashes(emoticons($r['post']))); // This is where the function's called
?>
</td>[/code]

Regards
Huggie
$post gets assigned whatever is passed to emoticons(), that's because it's specified when defining the function, like this:

[code=php:0]function emoticons($post){
  // Function code here
  return $post;
}
[/code]

So you can call the function with any variable you like, and it will get assigned to $post inside the function:

[code=php:0]$result = emoticons($r['post']);
[/code]

This takes whatever's in $r['post'], assigns it to $post inside the function and returns it as $result.

I hope that this makes sense.

Regards
Huggie
not really  ???
i got this from what i read it as:
[code] <?
function emoticon($post) {
  $emoticonarray = array(
      ':)'  => 'smile.gif',
      ':('  => 'sad.gif',
      ';)'  => 'wink.gif',
      ':P'  => 'tongue.gif'
  );

  foreach($emoticonarray as $emoticon => $img) {
      $search[] = $emoticon;
      $replace[] = '<img src="images/emotions/' . $img . '" alt="' . $emoticon . '" />';
  }
  $post = str_replace($search, $replace, $post);
  return $post;
}
$result = emoticons($r['post']);

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

and i get: Fatal error: Call to undefined function: emoticons() in /home/lordofth/public_html/forum/viewthread.php on line 91
You aren't echoing it anymore...

Try this:

[code]<?php
function emoticon($post) {
  $emoticonarray = array(
      ':)'  => 'smile.gif',
      ':('  => 'sad.gif',
      ';)'  => 'wink.gif',
      ':P'  => 'tongue.gif'
  );

  foreach($emoticonarray as $emoticon => $img) {
      $search[] = $emoticon;
      $replace[] = '<img src="images/emotions/' . $img . '" alt="' . $emoticon . '" />';
  }
  $post = str_replace($search, $replace, $post);
  return $post;
}
$result = emoticons($r['post']);

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

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.