Modify HTML code with an image.
Moderator: General Moderators
-
MarioAllStar
- Forum Newbie
- Posts: 5
- Joined: Tue Dec 23, 2003 3:41 pm
Modify HTML code with an image.
[This post was extremely unclear and sloppy. Please read my next post]
Last edited by MarioAllStar on Tue Dec 23, 2003 5:41 pm, edited 1 time in total.
-
MarioAllStar
- Forum Newbie
- Posts: 5
- Joined: Tue Dec 23, 2003 3:41 pm
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!
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
Code: Select all
<a href=>www.site.com<a>around the image.
I hope this clears some things up!
You could try something along the lines of:
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....
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
?>Not sure if that was what you were asking....
-
MarioAllStar
- Forum Newbie
- Posts: 5
- Joined: Tue Dec 23, 2003 3:41 pm
-
MarioAllStar
- Forum Newbie
- Posts: 5
- Joined: Tue Dec 23, 2003 3:41 pm
Acually, I have a question.
Ok, If both img1 and img2 have their own sites that they link to, what is the 'default' link used for?
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/">';-
MarioAllStar
- Forum Newbie
- Posts: 5
- Joined: Tue Dec 23, 2003 3:41 pm
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.?
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.?