almightyegg Posted October 23, 2006 Share Posted October 23, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/ Share on other sites More sharing options...
trq Posted October 23, 2006 Share Posted October 23, 2006 [quote]i know there is something iffy with the function[/quote]Can you atleast make the effort to describe your problem. Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113084 Share on other sites More sharing options...
almightyegg Posted October 23, 2006 Author Share Posted October 23, 2006 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 76line 76 is: function emoticon($r['post']) { Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113087 Share on other sites More sharing options...
almightyegg Posted October 23, 2006 Author Share Posted October 23, 2006 anyone??? Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113168 Share on other sites More sharing options...
trq Posted October 23, 2006 Share Posted October 23, 2006 That is NOT how you define an argument for a function. read [url=http://php.net/functions]here[/url]. Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113172 Share on other sites More sharing options...
almightyegg Posted October 23, 2006 Author Share Posted October 23, 2006 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?? Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113176 Share on other sites More sharing options...
HuggieBear Posted October 23, 2006 Share Posted October 23, 2006 Your getting confused between defining a function and calling one...Try this:[code]<?phpfunction 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 functionecho stripslashes($r['username']);?></td><td style="width:80%;background-color:#101010;"><?phpecho nl2br(stripslashes(emoticons($r['post']))); // This is where the function's called?></td>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113179 Share on other sites More sharing options...
almightyegg Posted October 23, 2006 Author Share Posted October 23, 2006 it doesnt recognise $post as $r['post'] surely?? but that's now at least showing the page :) Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113182 Share on other sites More sharing options...
HuggieBear Posted October 23, 2006 Share Posted October 23, 2006 $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.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113187 Share on other sites More sharing options...
almightyegg Posted October 23, 2006 Author Share Posted October 23, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113188 Share on other sites More sharing options...
trq Posted October 23, 2006 Share Posted October 23, 2006 You have defined the function as emoticon() not emoticons().[code=php:0]$result = emoticon($r['post']);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113189 Share on other sites More sharing options...
almightyegg Posted October 23, 2006 Author Share Posted October 23, 2006 that removed the error message but still no smileys :( Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113191 Share on other sites More sharing options...
HuggieBear Posted October 23, 2006 Share Posted October 23, 2006 You aren't echoing it anymore...Try this:[code]<?phpfunction 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113202 Share on other sites More sharing options...
almightyegg Posted October 23, 2006 Author Share Posted October 23, 2006 yay it works! thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113207 Share on other sites More sharing options...
HuggieBear Posted October 23, 2006 Share Posted October 23, 2006 What I did was put $result into this line:[code=php:0]echo nl2br(stripslashes($result));[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113208 Share on other sites More sharing options...
almightyegg Posted October 23, 2006 Author Share Posted October 23, 2006 o righty ho!! :D Quote Link to comment https://forums.phpfreaks.com/topic/24828-can-somebody-help-me-debug-this/#findComment-113218 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.