Page 1 of 1
Modify HTML code with an image.
Posted: Tue Dec 23, 2003 3:41 pm
by MarioAllStar
[This post was extremely unclear and sloppy. Please read my next post]
Posted: Tue Dec 23, 2003 4:55 pm
by m3rajk
do you mean have an image that changes?
what your asking for.. at least as stated, isn't clear to me. please clarify.
Posted: Tue Dec 23, 2003 5:40 pm
by MarioAllStar
Sorry about that!
Ok, I want to generate an image using a PHP script. I also want this image to modify the HTML source of the document that it is in. I want to be able to define what picture will be generated and the HTML source to be added in by the image.
For example, I have my avatar in a forum be the PHP generated image. Normally, you could have your avatar link to anything (in some forums it links to your profile) but the PHP script would make my avatar link to any site I choose by inserting
around the image.
I hope this clears some things up!

Posted: Tue Dec 23, 2003 7:42 pm
by evilMind
You could try something along the lines of:
Code: Select all
<?php
// array of images that you could use.
$imageNames = array( 'img1.jpg' , 'img2.jpg' , 'etc' );
// select a random image from the above array
$imageToBeUsed = $imageNames[rand(0,count($imageNames)];
// url encode in case there is a space or special character in the file name
$imageToBeUsed = urlencode($imageToBeUsed);
// Use a switch to determine what to do based on the image you are going to display
switch( $imageToBeUsed ) {
case 'img1.jpg': $link = '<a href="http://foo.com/">';
break;
case 'img2.jpg': $link = '<a href="http://bar.com/'>';
break;
default: $link = '<a href="http://default_link.com/">';
}
echo $link; // echo the link to use for the image choosen
echo '<img src="imageCreationFilename.php?useImage="' . $imageToBeUsed . '" />';
echo '</a>'; // close the link
?>
Then in the image creation php page, you would then display the proper image based on what was passed in via the $_GET variable.
Not sure if that was what you were asking....
Posted: Tue Dec 23, 2003 7:53 pm
by MarioAllStar
Thanks I'll try that one out!
If anybody here has any disagreements and think it won't work please post here.
Posted: Tue Dec 23, 2003 9:58 pm
by MarioAllStar
Acually, I have a question.
Code: Select all
// Use a switch to determine what to do based on the image you are going to display
switch( $imageToBeUsed ) {
case 'img1.jpg': $link = '<a href="http://foo.com/">';
break;
case 'img2.jpg': $link = '<a href="http://bar.com/'>';
break;
default: $link = '<a href="http://default_link.com/">';
Ok, If both img1 and img2 have their own sites that they link to, what is the 'default' link used for?
Posted: Thu Dec 25, 2003 3:45 pm
by vigge89
that is if the script can't find the case returned, ie;
if $imageToBeUsed contains "img11.jpg", and if it's not declared what to do with "img11.jpg" in the switch(), it will execute the default
Posted: Thu Dec 25, 2003 4:05 pm
by MarioAllStar
Thank you that helps!
Also, is there a way to insert different HTML code into the document which calls for the image. You know, instead of the <a href="
http://foo.com/">. For example, add in some Javascript code to the HTML document and have the image execute that script.?