My Markup Validator

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
$_ENV['http_referrer'] or something similar to that. I don't use it all that often.
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
Hooray for phpBB:
markupvalid.php


Cant it say what code is wrong and what it should be replaced with??
Edit:
OMG! www.google.com :
markupvalid.php


www.microsoft.com:
markupvalid.php
 
Last edited:

nonsensep

New Member
Messages
39
Reaction score
0
Points
0
I released version 1.2. It's under the same URI. Instead of it saying, for example:

Valid
XHTML 1.0 Strict

It would say this:

XHTML 1.0 Strict
0 Errors, 0 Warnings

It also replaces badly written code. And it's more efficient.

Another change is that version 1.2 supports using "?uri=referer". But it doesn't give "referer" to W3C. It replaces it with $_SERVER["HTTP_REFERER"] then gives it to W3C. That way, there won't be a problem with the cache if more than one site uses "?uri=referer".

EDIT: Also, I forgot to mention that I don't have cache working fully yet. But I'm working on it. I'll also be working on a CSS validator like this.
 
Last edited:

engel

New Member
Messages
54
Reaction score
0
Points
0
Any chance that the source for this will be released?
 

arsonistx

New Member
Messages
308
Reaction score
0
Points
0
You could cache it on an hourly basis or so. Sessions would be too short :p

It would either be waiting a few seconds for the image to load or an hour for it to cache, lol. I wouldn't really mind if the image took a little while to load.
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Ah, I guessed as much, sending curl requests to W3C's validator. I was wondering how someone with enough knowledge to write a validator was having trouble with basic PHP concepts .. heh...

A really basic version of this script would be as follows

1. Curl a request to http://validator.w3.org/ with the site name
2. Get the results and parse it.
3. Use GD Lib to generate an image.


It would have been awesome if you wrote your own validator, in this case you're leeching off another's service. Its only a matter of time before they ban an IP from accessing their validator. If they wanted to do a service like this, they could have but it just puts to much stress on their server so they didn't.
 

eminemix

Member
Messages
350
Reaction score
0
Points
16
It would have been awesome if you wrote your own validator, in this case you're leeching off another's service. Its only a matter of time before they ban an IP from accessing their validator. If they wanted to do a service like this, they could have but it just puts to much stress on their server so they didn't.

I think the W3 Validator is an Open Source. Look here, http://validator.w3.org/source/ !

You can get it here.
Now, you don't need to validate it at w3, you will do that here. ;)

Keep up the good work !
 
Last edited:

nonsensep

New Member
Messages
39
Reaction score
0
Points
0
I don't use curl. I use fsockopen. Here's the source:

Code:
<?php

$uri = $_GET["uri"];
$charset = $_GET["charset"];
$doctype = $_GET["doctype"];

if (trim(strtolower($uri)) == "referer") $uri = $_SERVER["HTTP_REFERER"];

$fp = fsockopen("validator.w3.org", 80, $errno, $errstr, 30);
if ($fp)
{
    $send  = "GET /check?uri=" . $uri;
    if (trim($charset) !== "") $send .= "&charset=" . $charset;
    if (trim($doctype) !== "") $send .= "&doctype=" . $doctype;
    $send .= " HTTP/1.1\r\n";
    $send .= "Host: validator.w3.org\r\n";
    $send .= "Accept: text/html;\r\n";
    $send .= "Accept-Language: en-us, en;\r\n";
    $send .= "Connection: Close\r\n\r\n";

    fwrite($fp, $send);
    $out = "";
    while (!feof($fp))
    {
        $out .= fgets($fp, 128);
    }
    fclose($fp);

    $im = imagecreatetruecolor(176, 31);

    $body = substr($out, strpos($out, "<body"), strpos($out, ">", strpos($out, "</body")) - strpos($out, "<body"));

    $h2 = trim(strip_tags(substr($body, strpos($body, ">", strpos($body, "<h2")) + 1, strpos($body, "</h2>", strpos($body, ">", strpos($body, "<h2"))) - strpos($body, ">", strpos($body, "<h2")) - 1)));

    $result = str_replace(" validation", "", trim(strip_tags(substr($body, strpos($body, ">", strpos($body, "<td", strpos($body, "Result"))) + 1, strpos($body, "</td>", strpos($body, ">", strpos($body, "<td", strpos($body, "Result")))) - strpos($body, ">", strpos($body, "<td", strpos($body, "Result"))) - 1))));
    
    if (stripos($h2, "valid") != FALSE)
    {
        $doctype = trim(strip_tags(substr($body, strpos($body, ">", strpos($body, "<td", strpos($body, 'for="doctype"'))) + 1, strpos($body, "<select", strpos($body, ">", strpos($body, "<td", strpos($body, 'for="doctype"')))) - strpos($body, ">", strpos($body, "<td", strpos($body, 'for="doctype"'))) - 1)));

        if (stripos($h2, "not") != FALSE)
        {
            $error = trim(substr($result, strpos($result, ",") + 1));
            $warning = "0 Warnings";
            $back = imagecolorallocate($im, 210, 61, 36);
        }
        else if (stripos($h2, "tentatively") != FALSE)
        {
            $error = "0 Errors";
            $warning = str_replace("w", "W", trim(substr($result, strpos($result, ",") + 1)));
            $back = imagecolorallocate($im, 85, 176, 90);
        }
        else
        {
            $error = "0 Errors"; 
            $warning = "0 Warnings";
            $back = imagecolorallocate($im, 85, 176, 90);
        }

        if (substr($warning, 0, 1) == "1") $warning = str_replace("(s)", "", $warning);
        else $warning = str_replace("(s)", "s", $warning);

    
        $string = $doctype . "\n" . $error . ", " . $warning;
        $font = "VeraBd.ttf";

    }
    else
    {
        $doctype = $h2;
        $back = imagecolorallocate($im, 210, 61, 36);

        $string = wordwrap($h2, 28);
        $font = "VeraMoBd.ttf";
    }

    imagefill($im, 0, 0, $back);

    $fore = imagecolorallocate($im, 255, 255, 255);

    imagettftext($im, 7, 0, 4, 13, $fore, $font, $string);

    header("Content-type: image/png");
    imagepng($im);
    imagedestroy($im);

}

?>

About the source code, I'll look into that; It'd be much more efficient that way. Except for it being CGI, which I don't prefer.

The problem with using my own code is that people might not trust that it works as well as say the W3C validator. Even if I use their source, it's not guaranteed to work exactly as their validator
 
Last edited:

eminemix

Member
Messages
350
Reaction score
0
Points
16
I think the real problem is that people don't care to have valid html/xhtml on their site.
When microsoft or google doesn't have it valid, they can't be a good example to others.
 

nonsensep

New Member
Messages
39
Reaction score
0
Points
0
Some people care to have valid code so that all of their viewers with different OS's, browser's, etc. can share the same viewing experience. Some people think that you don't need 100% perfect code for all your viewers to view the same thing. Others believe that you can't do certain things when trying to use valid code (not true). And finally some are just lazy and write awful markup.
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Curl, fsockopen.

No real difference except that curl would give you better performance.
 

nonsensep

New Member
Messages
39
Reaction score
0
Points
0
Curl, fsockopen.

No real difference except that curl would give you better performance.


well for now i'm going to put my project on hold. maybe forever. that is, once i find the time to interpret the perl code from the W3C's validator or write my own, i'll continue it.
 
Top