homepage Welcome to WebmasterWorld Guest from 54.205.189.156
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
xhtml and php
validation
shug




msg:1310072
 10:07 pm on Jun 2, 2005 (gmt 0)

Hello All,

New to PHP, infact just started to learn. My problem is this: I have just built my first website but have added a couple of php scripts (include files) for a counter etc (until I can write my own).

My site is in xhtml 1.0 transitional and the counter works fine but just checked the w3c validation site and it shows errors against my line 129 which is as follows:

<div id="counter"> <span class="countertext">you are visitor</span>
<?php include("counter.php");?>
<span class="countertext"> thank you.</span> </div>

My question is this: If php is a server side language why do I get xhtml errors. I take it the errors are in the counter.php file.

Hope this makes sense to you.
thanks for taking the time to help

Shug

 

twist




msg:1310073
 10:29 pm on Jun 2, 2005 (gmt 0)

The validator reads your pages script not your server side script.

Tick the "Show Source" on the validator and copy the line(s) that are giving you the errors.

shug




msg:1310074
 12:26 pm on Jun 3, 2005 (gmt 0)

Twist,

I did what you said and this is what I got back:
<div id="counter"><span class="countertext">you are visitor</span>
<img src=images/digits/1.gif><img src=images/digits/6.gif><img src=images/digits/9.gif> <span class="countertext"> thank you.</span> </div>
</div>

And these are the errors (15)on 1 line;

Line 128, column 15: an attribute value specification must be an attribute value literal unless SHORTTAG YES is specified

<img src=images/digits/1.gif><img src=images/digits/6.gif><img src=images/

Line 128, column 22: NET-enabling start-tag not immediately followed by null end-tag

<img src=images/digits/1.gif><img src=images/digits/6.gif><img src=images/

Line 128, column 22: required attribute "alt" not specified

<img src=images/digits/1.gif><img src=images/digits/6.gif><img src=images/

The 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>.

Line 128, column 22: end tag for "img" omitted, but OMITTAG NO was specified

<img src=images/digits/1.gif ><img src=images/digits/6.gif><img src=images/

You may have neglected to close a tag, or perhaps you meant to "self-close" a tag; that is, ending it with "/>" instead of ">".

Line 128, column 6: start tag was here

<img src=images/digits/1.gif><img src=images/digits/6.gif><img src=images/

Line 128, column 44: an attribute value specification must be an attribute value literal unless SHORTTAG YES is specified

...img src=images/digits/1.gif><img src=images/digits/6.gif><img src=images/digi

Line 128, column 51: NET-enabling start-tag not immediately followed by null end-tag

...=images/digits/1.gif><img src=images/digits/6.gif><img src=images/digits/9.gi

Line 128, column 51: required attribute "alt" not specified

...=images/digits/1.gif><img src=images/digits/6.gif><img src=images/digits/9.gi

Line 128, column 51: end tag for "img" omitted, but OMITTAG NO was specified

...=images/digits/1.gif><img src=images/digits/6.gif><img src=images/digits/9.gi

Line 128, column 35: start tag was here

<img src=images/digits/1.gif><img src=images/digits/6.gif><img src=images/

Line 128, column 73: an attribute value specification must be an attribute value literal unless SHORTTAG YES is specified

...img src=images/digits/6.gif><img src=images/digits/9.gif> <span class="c

Line 128, column 80: NET-enabling start-tag not immediately followed by null end-tag

...=images/digits/6.gif><img src=images/digits/9.gif> <span class="countert

Line 128, column 80: required attribute "alt" not specified

...=images/digits/6.gif><img src=images/digits/9.gif> <span class="countert

Line 128, column 80: end tag for "img" omitted, but OMITTAG NO was specified

...=images/digits/6.gif><img src=images/digits/9.gif> <span class="countert

Line 128, column 64: start tag was here

...s/1.gif><img src=images/digits/6.gif><img src=images/digits/9.gif> <span

thanks for your time.

encyclo




msg:1310075
 12:34 pm on Jun 3, 2005 (gmt 0)

<img src=images/digits/1.gif>

As the error messages say, you are missing the required alt attribute and you are missing the XHTML trailing slash on the img tag. You should also be quoting the attributes. So the above should read:

<img src="images/digits/1.gif" alt="your alt text here" />

shug




msg:1310076
 1:28 pm on Jun 3, 2005 (gmt 0)

This is where my ignorance of the php syntax comes in.
I realise that what you say is correct xhtml syntax

<img src="images/digits/1.gif" alt="your alt text here" />.

However, this must be part of the php include file and I dont know how to change it. The counter.php file has this code and is echo'd out

// print the image for that digit
echo "<img src=images/digits/$digit.$imgExtension>";

am I right that this needs changing? Sorry but very new at this. Thanks again.

twist




msg:1310077
 2:56 pm on Jun 3, 2005 (gmt 0)

I use string concatenation which I recall someone once said is not the best method to use. I honestly can't remember the preferred way to do it. Should probably ask so you don't start with a bad habit. Principle is still the same though.

// print the image for that digit
echo "<img src=images/digits/$digit.$imgExtension>";

Many ways to accomplish this, here are a few,

// use single quotes and escape them as necessary
echo '<img alt="description" src="images/digits/'. $digit . $imgExtension .'" />';

// use double quotes for php and escape them in the xhtml
echo "<img alt=\"description\" src=\"images/digits/". $digit . $imgExtension .\"" />";

// store everything in variables then concatenate
$image_begin = '<img alt="description" src="images/digits/';
$image_end = '" />';
echo $image_begin . $digit . $imgExtension . $image_end;

I use the first method.

shug




msg:1310078
 3:48 pm on Jun 3, 2005 (gmt 0)

Hi,

Thanks for your reply. Nearly there now but this is what has happend. I used this;

echo '<img alt="counter" src="images/digits/'. $digit . $imgExtension .'" />';

it now validates ok but my counter images are missing?

shug




msg:1310079
 5:27 pm on Jun 3, 2005 (gmt 0)

I tried all those methods above except the last one to no avail. But kept at it and got it to validate ok using this:

// print the image for that digit
echo "<img alt=\"counter\" src=\"images/digits/$digit.$imgExtension\" />";

Thanks both of you for your time.

Shug

twist




msg:1310080
 7:13 pm on Jun 3, 2005 (gmt 0)

lol, I see where I went wrong,

// print the image for that digit
echo "<img src=images/digits/$digit.$imgExtension>";

The dot between $digit and $imgExtension isn't for concatinating but is seperating the filename from extension. Sorry, wasn't paying attention.

echo '<img alt="text" src="images/digits/'. $digit .'.'. $imgExtension .'>"';

but the way you did it looks cleaner :)

shug




msg:1310081
 8:58 pm on Jun 3, 2005 (gmt 0)

thanks pure guess work on my part.

Am impressed with this forum and the willingness for others to help beginners like me.

Your time was appreciated. Thanks

Shug

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved