View Full Version : Smilies PHP script for blogs


MaGiCSuN
08-23-2003, 05:19 PM
With this script you can use smilies in your messages from your Blog. It does the same as on this forum, making : ) this smiley :) etc.

To use this function your host must support PHP and you also have to have a blog hosted at your own space. This is how it goes:


Make sure your host allows PHP. Most domains have PHP, so if you are hosted with someone that has a domain you are almost 99% sure you are allowed to use PHP

First you take your page where you're blog is located. In this tutorial i'm going to call it "blog.html" You just leave that page as it is, but you will not need that one to visit anymore. More on that later

Now we are going to make the page that replaces codes like this : ) into smilies. Open Notepad and add the following code to it:

<?
$Filename = "blog.html";

$smiliearray = array(
':|',
':|',
':|',
':|',
':|',
':|',
':|',
':|',
);

$imagearray = array(
'<img src="/smilies/wink.gif" border="0">',
'<img src="/smilies/sad.gif" border="0">',
'<img src="/smilies/happy.gif" border="0">',
'<img src="/smilies/tongue.gif" border="0">',
'<img src="/smilies/teeth.gif" border="0">',
'<img src="/smilies/angry.gif" border="0">',
'<img src="/smilies/frown.gif" border="0">',
'<img src="/smilies/shocked.gif" border="0">'
);

$File = fopen($Filename, "r");
echo str_replace($smiliearray, $imagearray, fread($File, filesize($Filename)));
fclose($File);
?>

You can edit the codes below "smiliearray" to your own codes. I have made them all ":|" in the code because of this forum. In order to make the script work you have to change them all to different ones. the <img> tags are the images that appear instead of that code. The codes and the images must be in the exact order matching each other. So first code matches first <img>, the second code matches the second image etc.

Now you save that file above as blog.php

You see that there is in the code above the line : filename="blog.html" . That code is nessecary to view the blog.html page on the blog.php page. So from now on you access your blog with blog.php instead of blog.html

Now you save some smilies to your harddrive, and put them in a folder named smilies When you are going to upload all the stuff you upload this folder instead of image by image

When you have everything upload blog.php and blog.html and the folder "smilies". You just continue updating on blog.html, DO NOT update on blog.php. It only links the smilies and your blog together :) It could be that when you have your blog.php file uploaded it is named as blog.php.txt. If so then right click on the file and choose "change name" and change it to blog.php and it should work now.

Love,
Mirna