/    Sign up×
Community /Pin to ProfileBookmark

ALT tag on every random image

Hi All,

I have a script for random image loading on refresh page. I need different alt tag on every image but not using iframes.

Can someone help me to figureout this problem. This is the script I have used for images.

<?php
$path = array();
$path[] = “images/dir1/”; // 0
$path[] = “images/dir2/”; // 1
$path[] = “images/dir3/”; // 2
$path[] = “images/dir4/”; // 3
$path[] = “images/dir5/”; // 4
$count = rand(0, 4); // max dir number
$dir = $path[$count];
$arr = array();
$cnt = 1;
foreach (glob($dir.”*.jpg”) as $file) {
$arr[] = $file;
$cnt = ($cnt + 1);
}
$number = rand(1, $cnt);
$content = “<img src=”{$arr[$number]}” alt=”RandomImage.” title=”Random Image” />”.”n”;
echo($content);
?>

Please help me.

Sunil Saini

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@jbezansonJun 19.2007 — you could define an arraqy of assorted alt tags then generate a random number to select one.
Copy linkTweet thisAlerts:
@A1ien51Jun 19.2007 — First off this is not JavaScript!

What is your problem exactly? You have no clue how to add it?

Add another array with the alt messages and reference it the same way that the path array value is added.

Eric
Copy linkTweet thisAlerts:
@sainisunilauthorJun 19.2007 — Thanks for your help.

Could you please let me know how can I add another array for alt tag.

Actually This script is written by my friend and he is not in touch with me.

I am a designer not a hard coder just simple html coder.

Please help.

Thanks in advance.

Sunil Saini
×

Success!

Help @sainisunil spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...