...

View Full Version : php image swap script not validating



vinny388
06-27-2007, 04:06 PM
Hi, hope this is the correct place.

I have a site that uses a fairly simple ( i say simple, i know nothing about php!) image swap script based on the current day.


<?php
$url = "http://www.cecilsrentarookie.co.uk/assets/images/spedeworth-fixtures/";
$monImage = "$url"."fix-3.jpg";
$tueImage = "$url"."fix-3.jpg";
$wedImage = "$url"."fix-1.jpg";
$thurImage = "$url"."fix-2.jpg";
$friImage = "$url"."fix-2.jpg";
$satImage = "$url"."fix-2.jpg";
$sunImage = "$url"."fix-2.jpg";
$d = date("D");
//Function that switches between date images based on the actual day of the week in $d
switch ($d)
{
case Mon:
echo "<img src=$monImage>\n";
break;
case Tue:
echo "<img src=$tueImage>\n";
break;
case Wed:
echo "<img src=$wedImage>\n";
break;
case Thu:
echo "<img src=$thurImage>\n";
break;
case Fri:
echo "<img src=$friImage>\n";
break;
case Sat:
echo "<img src=$satImage>\n";
break;
case Sun:
echo "<img src=$sunImage>\n";
}
?>

Now it all works a treat, but the issue being that the site doesnt validate due to 4 errors relating to this script. I have tried and tried and cannot suss out what the problem is or how to fix it?

Errors:


Below are the results of checking this document for XML well-formedness and validity.

Error Line 149 column 9: an attribute value specification must be an attribute value literal unless SHORTTAG YES is specified.
<img src=http://www.cecilsrentarookie.co.uk/assets/images/spedeworth-fixtures/fi✉

Error Line 149 column 15: NET-enabling start-tag not immediately followed by null end-tag.
<img src=http://www.cecilsrentarookie.co.uk/assets/images/spedeworth-fixtures/fiThis error may occur when there is a mistake in how a self-closing tag is closed, e.g '.../ >'. The proper syntax is '... />' (note the position of the space).



Error Line 149 column 15: required attribute "alt" not specified.
<img src=http://www.cecilsrentarookie.co.uk/assets/images/spedeworth-fixtures/fiThe attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.

Typical values for type are type="text/css" for <style> and type="text/javascript" for <script>.



Error Line 149 column 15: end tag for "img" omitted, but OMITTAG NO was specified.
<img src=http://www.cecilsrentarookie.co.uk/assets/images/spedeworth-fixtures/fiYou may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".

site is www.cecilsrentarookie.co.uk if u need too view.

thanks

Mwnciau
06-27-2007, 04:13 PM
<?php
$url = "http://www.cecilsrentarookie.co.uk/assets/images/spedeworth-fixtures/";
$monImage = "$url"."fix-3.jpg";
$tueImage = "$url"."fix-3.jpg";
$wedImage = "$url"."fix-1.jpg";
$thurImage = "$url"."fix-2.jpg";
$friImage = "$url"."fix-2.jpg";
$satImage = "$url"."fix-2.jpg";
$sunImage = "$url"."fix-2.jpg";
$d = date("D");
//Function that switches between date images based on the actual day of the week in $d
switch ($d)
{
case Mon:
echo '<img src="$monImage" alt="$monImage" />\n';
break;
case Tue:
echo '<img src="$tueImage" alt="$tueImage" />\n';
break;
case Wed:
echo '<img src="$wedImage" alt="$wedImage" />\n';
break;
case Thu:
echo '<img src="$thurImage" alt="$thurImage" />\n';
break;
case Fri:
echo '<img src="$friImage" alt="$friImage" />\n';
break;
case Sat:
echo '<img src="$satImage" alt="$satImage" />\n';
break;
case Sun:
echo '<img src="$sunImage" alt="$sunImage" />\n';
}
?>

That should validate correctly.

vinny388
06-27-2007, 04:27 PM
Hi, that doesn't work, it validates but now the images arent showing :confused:

Mwnciau
06-27-2007, 04:32 PM
Sorry about that:


<?php
$url = "http://www.cecilsrentarookie.co.uk/assets/images/spedeworth-fixtures/";
$monImage = "$url"."fix-3.jpg";
$tueImage = "$url"."fix-3.jpg";
$wedImage = "$url"."fix-1.jpg";
$thurImage = "$url"."fix-2.jpg";
$friImage = "$url"."fix-2.jpg";
$satImage = "$url"."fix-2.jpg";
$sunImage = "$url"."fix-2.jpg";
$d = date("D");
//Function that switches between date images based on the actual day of the week in $d
switch ($d)
{
case Mon:
echo '<img src="'.$monImage.'" alt="'.$monImage.'" />\n';
break;
case Tue:
echo '<img src="'.$tueImage.'" alt="'.$tueImage.'" />\n';
break;
case Wed:
echo '<img src="'.$wedImage.'" alt="'.$wedImage.'" />\n';
break;
case Thu:
echo '<img src="'.$thurImage.'" alt="'.$thurImage.'" />\n';
break;
case Fri:
echo '<img src="'.$friImage.'" alt="'.$friImage.'" />\n';
break;
case Sat:
echo '<img src="'.$satImage.'" alt="'.$satImage.'" />\n';
break;
case Sun:
echo '<img src="'.$sunImage.'" alt="'.$sunImage.'" />\n';
}
?>

vinny388
06-27-2007, 05:07 PM
Thats ok bud, lol

Erm, image now appears but I have the /n visble on page and the alt tage seems to pull in the url?

Sorry bout this and thanks for helping me :)

Mwnciau
06-27-2007, 05:09 PM
<?php
$url = "http://www.cecilsrentarookie.co.uk/assets/images/spedeworth-fixtures/";
$monImage = "$url"."fix-3.jpg";
$tueImage = "$url"."fix-3.jpg";
$wedImage = "$url"."fix-1.jpg";
$thurImage = "$url"."fix-2.jpg";
$friImage = "$url"."fix-2.jpg";
$satImage = "$url"."fix-2.jpg";
$sunImage = "$url"."fix-2.jpg";
$d = date("D");
//Function that switches between date images based on the actual day of the week in $d
switch ($d)
{
case Mon:
echo '<img src="'.$monImage.'" alt="'.$monImage.'" />';
break;
case Tue:
echo '<img src="'.$tueImage.'" alt="'.$tueImage.'" />';
break;
case Wed:
echo '<img src="'.$wedImage.'" alt="'.$wedImage.'" />';
break;
case Thu:
echo '<img src="'.$thurImage.'" alt="'.$thurImage.'" />';
break;
case Fri:
echo '<img src="'.$friImage.'" alt="'.$friImage.'" />';
break;
case Sat:
echo '<img src="'.$satImage.'" alt="'.$satImage.'" />';
break;
case Sun:
echo '<img src="'.$sunImage.'" alt="'.$sunImage.'" />';
}
?>

What do you mean by pull in the url?

vinny388
06-27-2007, 05:12 PM
What do you mean by pull in the url?

When you hover over the image, instead of displaying what is set as the alt tag, it displays the url instead

vinny388
06-27-2007, 05:17 PM
It's ok, I have done it, simply renaming the alt tag worked, just looked different to the normal alt tags thats all.

Thanks alot for your help, much appreciated :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum