Jump to content

problems with arrays


jasonc

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.