gtal3x Posted October 31, 2007 Share Posted October 31, 2007 For some reason the variable $smilies wont return the img puth instead is displaying "Array" anny solution? <?php $body = ""; function smilies($text) { $smilies = array( "" => "smile1.gif", "" => "wink.gif", "" => "grin.gif" ); $smiliesK = array_keys($smilies); $newtext = str_replace($smiliesK, "<img src='images/smilies/$smilies'>", $text); // The error is here in $smilies return $newtext; } echo smilies($body); ?> Quote Link to comment Share on other sites More sharing options...
Orio Posted October 31, 2007 Share Posted October 31, 2007 $smilies is an array, and in the str_replace (second parameter) you treating it as a string.. Orio. Quote Link to comment Share on other sites More sharing options...
gtal3x Posted October 31, 2007 Author Share Posted October 31, 2007 Am not really good with arrays... so i just cant understand whats wrong... if you just tell me the right way to do it ill appreciate it $smilies is an array, and in the str_replace (second parameter) you treating it as a string.. Orio. Quote Link to comment Share on other sites More sharing options...
Orio Posted October 31, 2007 Share Posted October 31, 2007 <?php $body = ""; function smilies($text) { $smilies = array( "" => "smile1.gif", "" => "wink.gif", "" => "grin.gif" ); $images = array(); foreach($smilies as $smile => $filename) $images[$smile] = "<img src='images/smilies/".$filename."'>"; $smiliesK = array_keys($smilies); $newtext = str_replace($smiliesK, $images, $text); // The error is here in $smilies return $newtext; } echo smilies($body); ?> Orio. Quote Link to comment Share on other sites More sharing options...
gtal3x Posted October 31, 2007 Author Share Posted October 31, 2007 Thanks a lot :) Quote Link to comment 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.