<?php /* This script has been written for mysql but the code shouldnt be too different to this. The table required is a table called: smilies below the sql query to create such a table.
CREATE TABLE smilies ( id INT( 10 ) NOT NULL AUTO_INCREMENT , smilie VARCHAR( 10 ) NOT NULL , image VARCHAR( 30 ) NOT NULL , PRIMARY KEY ( id ) );
example usage: After pulling information from the database call the function smilies eg: smilies($row['somedate']); would replace all instances of the smilies from the database with the appropriate html/image.
*/ function smilies($text){ $path="image"; //Specify the direcory in which images are stored $sql = "SELECT smilie, image FROM smilies"; //Select the smilies from the database //along with the names of the image files to //replace them $rs = mysql_query($sql); //Run the query while($row = mysql_fetch_array($rs)) { //Loop through the results creating two arrays $smilies[] = $row['smilie']; //Create array of smilie texts $images[] = "<img src='" . $path . "/" . $row['image'] . "'>"; //create array of image replacments with the html in it. } $text=str_replace($smilies, $images, $text);//Replace the smilies with the images. } ?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.