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); ?> Link to comment https://forums.phpfreaks.com/topic/75577-solved-array-not-working/ 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. Link to comment https://forums.phpfreaks.com/topic/75577-solved-array-not-working/#findComment-382398 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. Link to comment https://forums.phpfreaks.com/topic/75577-solved-array-not-working/#findComment-382406 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. Link to comment https://forums.phpfreaks.com/topic/75577-solved-array-not-working/#findComment-382408 Share on other sites More sharing options...
gtal3x Posted October 31, 2007 Author Share Posted October 31, 2007 Thanks a lot :) Link to comment https://forums.phpfreaks.com/topic/75577-solved-array-not-working/#findComment-382410 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.