replace each letter with a bit of html code?
hi, i am trying to make my website a little bit more fancy by getting this bit where it reads from text files and echos it to change each letter with something like this:
<img src="images/<?php //origional letter ?>.jpg" border=0>
just like the image counters but with a whole text document and with letters and numbers insted of just numbers if you get what i meen. i cannot figure out how those image counters work. i have one on my website but still can not figure it out and it has a funny bit of code in it which only does numbers.
thanks, dandono
Re: replace each letter with a bit of html code?
Will you attatch the source code and all sub folders/images of your current counter? Ill look at it. Thats a crazy idea. Sound cool to me. :bigyello:
1 Attachment(s)
Re: replace each letter with a bit of html code?
it is an idea that is ment to make all the text look cool insted of just fonts. here is my current counter this is something i found on the internet a few weeks ago because i did not under stand how to make an image counter.
http://www.vbforums.com/attachment.p...id=37049&stc=1
Re: replace each letter with a bit of html code?
Here is my breakdown of the php program.
What i did is simply copy the text and add //descriptions b4 the code.
This way you will know what its saying. OK
PHP Code:
<?
//Defines the location of the counter.dat file
$counterfile = "D:/inetpub/xproot/counter/counter.dat";
//defines the location of the image web folder "place the images here"
$imagedirectory = "";
//defines digit as an integer with 4 spaces.. to be used later in the program.
$digits = 4;
//defines the file open commmand .. "r" is for read
$opencount = @fopen($counterfile,"r");
$currentcount = fread($opencount, filesize($counterfile));
//Closes the file afterwards
fclose($opencount);
//declares that a new variable $newcount and says that it is the same as the above variable $newcount
$newcount = $currentcount;
//I believe this adds an increment to counter in memory
++$newcount;
$numdigits = strlen($newcount);
//catches any errors by checking to see if the count is less than "0"
if ($numdigits > $digits) {
$newcount = "0";
//if its not less than 0 then
} else {
}
//it defines $actdigits saying its = to strlen($newcount)
$actdigits = strlen($newcount);
//>---------------------------------------------------------------------------<
//> To use images other than gifs, you will need to modify the file extension <
//> after the 'else' statement in the following loop. <
//>---------------------------------------------------------------------------<
//while the number is 0 then use the 0.gif
for ($a=0; ; $a++) {
if ($a == $digits) {
break;
} else {
$img[$a] = "$imagedirectory";
$img[$a] .= "0.gif";
}
}
//>---------------------------------------------------------------------------<
//> To use images other than gifs, you will need to modify the file extension <
//> after the $showdig variable in the following loop. <
//>---------------------------------------------------------------------------<
for ($a=0; ; $a++) {
if ($a == $actdigits) {
break;
} else {
$showdig = substr($newcount, $a, 1);
$img[$digits - $actdigits + $a] = "$imagedirectory";
$img[$digits - $actdigits + $a] .= "$showdig.gif";
}
}
//the display block = nada
$displayblock = "";
for ($a=0; $a < $digits; $a++){
$displayblock .= "<td><img src=$img[$a]></td>";
}
//open the $counterfile again to "w" (write)
$opennewcount = @fopen($counterfile,"w");
//write to file the $newcount from the top of the code
@fwrite($opennewcount, $newcount);
//close file
fclose ($opennewcount);
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body bgcolor="#FFFFFF">
<?
//show the block with the new number displayed by images.
echo $displayblock
?>
</table>
</body>
</html>
In order to have it replace every character on a page... you would need to define every character A-Z 0-9 have a image ready to replace them... possible include the php file using an includes tag.. But the good news is you can get rid of the counter suff.. you dont need to add 1 to the counter every time.
The text would need to be written to the .dat file and then read again on refresh.. problably the other way around. The image would be read on pageload.. and then written to if there where a change.
Thats sounds like a good project,fun too. You could be on to something if you could get it to work.
Hope that helped. If not post any other questions here. I'd be glad to assist.
:thumb:
Re: replace each letter with a bit of html code?
i am realy stuck on this project. i cant get it to display every letter. i cant even get it to display letters. what do i need to do with this to get it to do them two things?
Re: replace each letter with a bit of html code?
Did you read the prior reply?
Look through there... i broke down the code.
You would need to declare all letters and replace them with the corresponding images.
Its to large of a project for me to do for you. :eek:
What you dont have to do is add to the counter each page load.
It would be easier if you simply stored the characters in the .dat and then read it.
Here is some pseudocode for the job
-------------------------
start php
define the location of your images
define each character ($a=a or $g=g)
open .dat to read "r"
use "for" statement to replace letters with images
end php
It is im sure harder than that. I've not done it B4 but ive created counters b4.
Its going to be a project.. but dont give up.
Re: replace each letter with a bit of html code?
ok i figured how to get around one of my problems. i know this should be in a different thread but how do you calculate how many chars are in a text doc of a string?
Re: replace each letter with a bit of html code?
If you declared the text as a string.. i dont know if thats the best way to do it.. maybe someone else can help.. but if you do.. then you could use this method to count Characters.
http://us2.php.net/strlen
Re: replace each letter with a bit of html code?
I think you should use modulo from something. 3324 for example, has 3 thousads, 3 hundreds, 2 tens and 4 ones. Now, we can then go for <img src='3.jpg' alt=''/><img src='3.jpg' alt=''/><img src='2.jpg'/ alt=''/><img src='4.jpg' alt=''/>. You should get the idea. Sorry I can't code it, me knows little on coding. Good luck.
Re: replace each letter with a bit of html code?
i have got an idea of what it will be like when it is finnished http://dws05.ath.cx/images/letters/
my images need to be remade because they are all off center and dont look that good.