Forum Moderators: coopster

Message Too Old, No Replies

Validation of PHP in <img>

Also want to insert link from ,inc.php file

         

D_Blackwell

7:07 am on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It works fine, but I would like to validate the XHTML

<div id="show-image">
<img src="<?php echo $selectedImage; ?>" <?php echo $imageSize[3]; ?> alt="Random image selected from Artist Galleries." />
</div>

2 warnings and five errors.

character "<" is the first character of a delimiter but occurred as data

unclosed start-tag requires SHORTTAG YES

required attribute "alt" not specified

end tag for "img" omitted, but OMITTAG NO was specified

XML Parsing Error: Unescaped '<' not allowed in attributes values

XML Parsing Error: attributes construct error

The image width and height are correct, but px not specified. Do I care? Can I do anything about that or must it just be assumed?

The output is as expected. Am I abusing the HTML validator by expecting it to okay my PHP? (Incorrect and foolish on my part?)

<body>
<div id="show-image">
<img src="images/jewelry-box-c-inside.jpg" width="450" height="527" alt="Random image selected from Artist Galleries." />
</div>

..................................

<p>
<?php echo $caption; ?>
</p>

$caption is the artist. I would like to insert as link to artist page over just text. How far afield am I with what I have now? Too far? I can live with it as is, but after I got it up, thought that inserting the link would be a plus.

<?php
$images = array (
array ('file' => 'butterfly',
'caption' => 'artist name'),
array ('file' => 'stick',
'caption' => 'artist name'),
array ('file' => 'annas-nesting-time',
'caption' => 'artist name'),

et cetera

TheMadScientist

8:02 am on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you trying to validate the raw HTML with PHP or the output from the PHP?

Your HTML looks fine to me and a single error from the validator can trigger others... IOW The 'required attribute "alt" not specified' is obviously wrong, so there's some other error before and my guess is you need to validate the HTML output after the PHP is parsed + processed, not the HTML with the PHP mixed in.

I'm not sure how your pages are structured to tell you how to include a link to the artist page, but if the page is the artists name ($caption) with hyphens or something you could do something like:

<a href="/artist-directory/<?php echo strtolower(str_replace(' ','-',$caption)); ?>.html">Link Text Here</a>

rocknbil

4:46 pm on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Am I abusing the HTML validator by expecting it to okay my PHP?

Once your PHP outputs to the browser, it's no longer PHP, it's (X)HTML and this is what the validator validates. Unless you're validating by direct upload, then yes, that would kick thousands of errors, if it could. :-)

Without seeing the whole picture, I'd start looking here, or prior to it

character "<" is the first character of a delimiter but occurred as data

Sometimes the only way to find the culprit is by process of elimination, start commenting stuff out of your PHP, hit it again with the validator.

D_Blackwell

5:40 pm on Nov 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that was my problem with getting the page through the validator. I was testing validation by upload from a directory that was not processing the PHP. Now fine, and live URL validates fine. The only problem was my not understanding where I was going wrong; though pretty sure both HTML and PHP were fine. Just couldn't prove it at the time.
.............................

I couldn't get your suggestion for linking the Artists to work. Not sure where I went wrong and your solution, correctly implemented, might be a better choice.?

<a href="/artist-directory/<?php echo strtolower(str_replace(' ','-',$caption)); ?>.html">Link Text Here</a>
.............................

I wound up taking another look at the question and, combined with your suggestion, went with:

array ('file' => 'image-file-name',
'caption' => '<a href="../inlace-artists/artist-name-directory/artist-name.html">ARTIST NAME</a>'),

This seems to work perfectly. But that does not make it the best choice. Too simplistic and leaving something out.?
.............................

Would still like to replace:

<?php echo $imageSize[3]; ?>

with CSS insertion.
~ ~ ~

Put the following in the head and did not work.

<?php
if (isset ($imageSize)) {
?>
<style type="text/css" media="screen">
#show-image img {
width: <?php echo $imageSize[0]; ?>px; height: <?php echo $imageSize[1]; ?>px;
}
</style>
<?php } ?>

Is this wrong? It doesn't work, so feel like I am missing how to get $imageSize to insert? All other CSS is in external page and no conflicts there. I'm guessing that $imageSize is not set.?
.............................

Have found that I can't just check image dimensions by getting source from mouse gesture, or from Web Developer > View Source > View Source. Either option seems to generate the next random page? The image and Artist are different that what I see on the current page.

I have to use the Web Developer > View Source > View GeneratedSource to get the page actually being viewed.