Using preg_replace
you can map the emoticons and replace them with their corresponding image. Inserting the image directly or formatting an element using css
.
Note that the example will return <img "smiles/:].gif">
.
example:
$string = 'Lorem ipsum dolor sit amet, consectetur... :) :]';
$pattern = ['~(\:\))~' , '~(\:\])~'];
$replace = '<img "smiles/${1}.gif">';
echo preg_replace($pattern, $replace, $string);
output:
Lorem ipsum dolor sit amet, consectetur.... <img "smiles/:).gif"> <img "smiles/:].gif">
Using css
, just use the classes smiles_01
and smiles_02
with image size and background.
example:
$string = 'Lorem ipsum dolor sit amet, consectetur... :) :]';
$pattern = ['~(\:\))~' , '~(\:\])~'];
$replace = ['<div class="smiles_01"></div>' , '<div class="smiles_02"></div>'];
echo preg_replace($pattern, $replace, $string);
output:
Lorem ipsum dolor sit amet, consectetur... <div class="smiles_01"></div> <div class="smiles_02"></div>
What will Emoticon represent as a reserved word? e.g.: [smile] [joinha] ... because if so, you can treat these reserved words when showing the image in the news reading
– Paulo Weverton
No, exactly why... may be different "symbols" that the user insert
– Developer1903
What you’ve tried, and what went wrong?
– Bacco