Page 1 of 1
array question(smilies)
Posted: Mon Jun 14, 2004 2:36 pm
by HaVoC
I have made a simple chatroom, but I wish to put in smilies...
Would this work?
Code: Select all
<?php
$message[':)'] = '<img src="smile.jpg">';
?>
Posted: Mon Jun 14, 2004 2:56 pm
by feyd
have you tried it?
Posted: Mon Jun 14, 2004 3:09 pm
by dull1554
Code: Select all
$newpostinfo = $_POST['message'];
//start smiley replace
$newpostinfo = str_replace(':D','<img src=images/smiles/icon_biggrin.gif>',$newpostinfo);
$newpostinfo = str_replace(':)','<img src=images/smiles/icon_smile.gif>',$newpostinfo);
$newpostinfo = str_replace(':(','<img src=images/smiles/icon_sad.gif>',$newpostinfo);
$newpostinfo = str_replace(':o','<img src=images/smiles/icon_surprised.gif>',$newpostinfo);
$newpostinfo = str_replace('8O','<img src=images/smiles/icon_eek.gif>',$newpostinfo);
$newpostinfo = str_replace(':?','<img src=images/smiles/icon_confused.gif>',$newpostinfo);
$newpostinfo = str_replace('8)','<img src=images/smiles/icon_cool.gif>',$newpostinfo);
$newpostinfo = str_replace(':lol:','<img src=images/smiles/icon_lol.gif>',$newpostinfo);
$newpostinfo = str_replace(':x','<img src=images/smiles/icon_mad.gif>',$newpostinfo);
$newpostinfo = str_replace(':P','<img src=images/smiles/icon_razz.gif>',$newpostinfo);
//end smiley replace
thats what i use in my forum
Posted: Mon Jun 14, 2004 4:21 pm
by launchcode
Code: Select all
<?php
$message[':)'] = '<img src="smile.jpg">';
?>
That code won't replace smiley faces, but it will set-up the start of a replacement array which could be used with str_replace.
Why have you put slashes before the "quote marks" ? You don't need them when using single quotes around your string.
Posted: Mon Jun 14, 2004 7:36 pm
by HaVoC
feyd wrote:have you tried it?
Yeah I did and as 'launchcode' said it doesn't work.
Posted: Mon Jun 14, 2004 7:39 pm
by feyd
use dull's suggestion.. overall..
Posted: Mon Jun 14, 2004 7:55 pm
by markl999
Or another way (just saves loads of str_replace calls).
Code: Select all
<?php
$smilies = array(
':D',
':)'
);
$smiliesreplace = array(
'<img src="images/smiles/icon_biggrin.gif">',
'<img src="images/smiles/icon_smile.gif">'
);
$_POST['message'] = str_replace($smilies, $smiliesreplace, $_POST['message']);
Posted: Mon Jun 14, 2004 9:58 pm
by launchcode
Yeah, I would suggest the array route too - str_replace being made to work on arrays was one of the best moves the PHP developers made IMHO
