View Full Version : Example Code-Adding Smileys to your site

7th January 2005, 11:37 AM
Hi everyone,
this is some example code i thought i would share as alot of people here seem to have sites.

This work on any version of php after 4.0

$smileys_code = array(":)", ";)");
$smileys_images = array('smileys/smiley.gif','smileys/wink.gif');
$data = str_replace($smileys_code, $smileys_images, $data_pre);

this assumes that you have a variable called $data_pre which contains the text you want to add the smileys too.

This code can of course be used for other functions such as re-formatting text from a mysql database

when you store text in a mysql database it replaces
tage with \n tags.

my above code can be modfied to reverse this

$data = str_replace("\n", "
", $data_pre);

Probably not the most useful code but any mysql newbies should find it helpful

7th January 2005, 12:15 PM

Thanks islayer, that might help me on some of my projects :P

7th January 2005, 12:16 PM
could anyone who finds this helpfull post here.
im considering making this a regular thing.

7th January 2005, 12:55 PM
Originally posted by islayer@Jan 7 2005, 12:16 PM
could anyone who finds this helpfull post here.
im considering making this a regular thing.
That'd be cool... Fun coding in HTML and PHP.

Let it run for a while and then do up an article for AppleTalk for web designers!

7th January 2005, 07:42 PM
Nice work islayer,

that method sure beats the hell out of regular expressions, I can see myself using this many times.

7th January 2005, 07:46 PM
thanks guys for the compliments.
ill try and find something to share next.

i might throw in a javascript for using timouts and redirectons.

7th January 2005, 07:59 PM
Simple HTML redirection script.

Put it in your <HEAD> area

<META HTTP-EQUIV="Refresh" CONTENT="6; url=http://www.yourdomain.com">

7th January 2005, 08:05 PM
i use JS redirects in several of my scripts where i want to able to speficy a timeout and display a message.
html is good but JS is more powerful.
some browsers dont support the html way properly and some banner exchange programs will block you if you use html because it can be easily used to inflate hit counts

When you start to use functions to do things its more natural to use the same language you use to create the function to perform the task also.

10th January 2005, 09:34 AM
added to my first post how to change formatting on mysql text.
not useful for most people but this thread is aimed at beginners and php/sql newbies