Jump to content


Photo

can somebody help me debug this??


  • Please log in to reply
15 replies to this topic

#1 almightyegg

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

Posted 23 October 2006 - 11:13 AM

i know there is something iffy with the function :(

<?
    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>

Visit my Game - Under Construction

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 October 2006 - 11:54 AM

i know there is something iffy with the function


Can you atleast make the effort to describe your problem.

#3 almightyegg

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

Posted 23 October 2006 - 12:00 PM

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']) {
Visit my Game - Under Construction

#4 almightyegg

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

Posted 23 October 2006 - 02:25 PM

anyone???
Visit my Game - Under Construction

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 October 2006 - 02:31 PM

That is NOT how you define an argument for a function. read here.

#6 almightyegg

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

Posted 23 October 2006 - 02:35 PM

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??
Visit my Game - Under Construction

#7 HuggieBear

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

Posted 23 October 2006 - 02:37 PM

Your getting confused between defining a function and calling one...

Try this:

<?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>

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

#8 almightyegg

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

Posted 23 October 2006 - 02:41 PM

it doesnt recognise $post as $r['post'] surely?? but that's now at least showing the page :)
Visit my Game - Under Construction

#9 HuggieBear

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

Posted 23 October 2006 - 02:49 PM

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

function emoticons($post){
   // Function code here
   return $post;
}

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

$result = emoticons($r['post']);

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
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

#10 almightyegg

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

Posted 23 October 2006 - 02:53 PM

not really  ???
i got this from what i read it as:
<?
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>

and i get: Fatal error: Call to undefined function: emoticons() in /home/lordofth/public_html/forum/viewthread.php on line 91

Visit my Game - Under Construction

#11 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 October 2006 - 02:56 PM

You have defined the function as emoticon() not emoticons().

$result = emoticon($r['post']);


#12 almightyegg

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

Posted 23 October 2006 - 02:58 PM

that removed the error message but still no smileys  :(
Visit my Game - Under Construction

#13 HuggieBear

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

Posted 23 October 2006 - 03:32 PM

You aren't echoing it anymore...

Try this:

<?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>

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

#14 almightyegg

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

Posted 23 October 2006 - 03:40 PM

yay it works! thanks :)
Visit my Game - Under Construction

#15 HuggieBear

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

Posted 23 October 2006 - 03:41 PM

What I did was put $result into this line:

echo nl2br(stripslashes($result));

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

#16 almightyegg

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

Posted 23 October 2006 - 03:56 PM

o righty ho!! :D
Visit my Game - Under Construction




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users