jasonc Posted April 24, 2010 Share Posted April 24, 2010 I am not sure how i correctly create or access the array fields, can someone please check my code and advise what i may be doing wrong as the $textstring is not getting changed at all. emoticons.php <? // i have given just few of the icons as its a long file. $emoticons = array( '0:-)' => 'angel.gif', '>:-(' => 'angry.gif>', '(applause)' => 'applause.gif', ':-)' => 'biggthumpup.gif', '(bow)' => 'bow.gif', ':-)' => 'censored.gif', '(clap)' => 'clap_hands.gif', ':-)' => 'confused.gif' ) main.php <? include("emoticons.php"); for ($i = 0; $i < count($emoticons); $i++) { ?><a href="#" onclick="AddSmiley('<?=$emoticons[$i][0];?>');return false"><img src="images/emoticons_<?=$emoticons[$i][1];?>"></a><? } function convert_emoticons($textstring) { include("emoticons.php"); for ($i = 0; $i < count($emoticons); $i++) { $textstring = str_replace($emoticons[$i][0], '<img src="images/emoticons_' . $emoticons[$i][1] . '>', $textstring); } return ($textstring); } ?> Link to comment https://forums.phpfreaks.com/topic/199618-problems-with-arrays/ Share on other sites More sharing options...
Alex Posted April 24, 2010 Share Posted April 24, 2010 Your problem is that you're trying to access the members of the array as if it's a multidimensional array, which it's not. function convert_emoticons($textstring){ include("emoticons.php"); foreach($emoticons as $symbol => $filename) { $textstring = str_replace($symbol, '<img src="images/emoticons_' . $filename . '>', $textstring); } return $textstring; } Link to comment https://forums.phpfreaks.com/topic/199618-problems-with-arrays/#findComment-1047779 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.