Jump to content

Archived

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

almightyegg

can somebody help me debug this??

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]

Share this post


Link to post
Share on other sites
[quote]i know there is something iffy with the function[/quote]

Can you atleast make the effort to describe your problem.

Share this post


Link to post
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']) {

Share this post


Link to post
Share on other sites
That is NOT how you define an argument for a function. read [url=http://php.net/functions]here[/url].

Share this post


Link to post
Share on other sites
that tutorial made no sense to me  ???

is it that im trying to name it at the same time as making a function? if so how do i correct it??

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
it doesnt recognise $post as $r['post'] surely?? but that's now at least showing the page :)

Share this post


Link to post
Share on other sites
$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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
You have defined the function as emoticon() not emoticons().

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
What I did was put $result into this line:

[code=php:0]echo nl2br(stripslashes($result));
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites

×

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.