Replace Characters with Emoticon Icons Array Tutorial

Published :
Author :
Adam Khoury
Learn to use PHP to change character sequences into emoticons or icons by using the str_replace function. You will want to alter the string data as it comes out of the MySQL database for display, not when the data is being inserted into the database. <?php $db_str = "Show me some <3 right now. It is raining today [umbr], that gives me peace [peace]."; echo $db_str; echo "<hr />"; $chars = array("<3", "[peace]", "[umbr]"); $icons = array("&#10084;", "&#9774;", "&#9730;"); $new_str = str_replace($chars,$icons,$db_str); echo $new_str; ?>