Dino
Dino

Reputation: 1457

How to W3C validate php image resize script

I use a php image resize script which is invoked using:

<img src="/images/image.php?img=test.png&maxw=100&maxh=100" alt="This is a test image" />

but this does not W3C validate. Are there anyways to get this to validate?

Upvotes: 2

Views: 381

Answers (3)

Fabian
Fabian

Reputation: 3495

If you output such URLs from PHP you can use htmlentities() to automatically convert e.g. & to &amp;

htmlentities — Convert all applicable characters to HTML entities

Example:

$path = "/images/image.php?img=test.png&maxw=100&maxh=100";
$path = htmlentities($path);
echo $path;

This would output this in your html:

/images/image.php?img=test.png&amp;maxw=100&amp;maxh=100

Upvotes: 0

oezi
oezi

Reputation: 51817

since you havn't given an exact eror-message, i have to assume the validation fails because of the ampersands. just take a look at the error description (wich also should be directly linked to from the validation-report, so you could have easily found this on your own) to see how to solve this.

To avoid problems with both validators and browsers, always use &amp; in place of & when writing URLs in HTML.

that said, just change your code to:

... src="/images/image.php?img=test.png&amp;maxw=100&amp;maxh=100" ...

Upvotes: 4

No Results Found
No Results Found

Reputation: 102824

It has nothing to do with PHP. All you need to do is turn those & characters into entities:

<img src="/images/image.php?img=test.png&amp;maxw=100&amp;maxh=100" alt="This is a test image" />

Really though, it's not that big of a deal. No browser (that I'm aware of) will misinterpret this, but if you want perfect validation then that's what you need to do.

Upvotes: 2

Related Questions