Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I was trying to find a way to see if my site's code was valid or not but I continuously going over to W3 Validator so I decided to make an "API" however it really isn't!

I just wanted to know if anybody can find a better solution to the one I have made. This is what I currently use, with the usage of ?uri=http://www.mydomain.com :

<?php
if(!$_GET['uri']) {
echo "No URI!";
}
else {
 $CheckURI = "http://validator.w3.org/check?uri=".$_GET['uri'];
 $URL = file_get_contents($CheckURI);
 $Start = strpos($URL, "<title>") + 7;
 $End = strpos($URL, "</title>");
 $Title = substr($URL, $Start, $End-$Start);
 if(preg_match('[Invalid]',$Title)) {
     //Code is INVALID
     echo "<a href='$CheckURI' title='This is not good!' target='_BLANK'>INVALID Source</a>";
 }
 elseif(preg_match('[Valid]',$Title)) {
     //Code is VALID
     echo "<a href='$CheckURI' title='Check It Yourself!' target='_BLANK'>Valid Source</a>";
 }
 else {
    //It Went WRONG
    echo "";
 }
}
share|improve this question

closed as not constructive by John Conde Oct 31 '12 at 18:11

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

    
the only thing you read from the results page is valid/invalid? What do you do with the results? How do you send the pages to the validator? And by that I mean which headers and code. –  PatomaS Oct 31 '12 at 13:30

1 Answer 1

I don't think W3C had your use case in mind when they made the validator. Why not run your own? The script you made is going to be very slow because it is relaying all requests. Also, your script won't run cleanly on E_STRICT. Also, your script doesn't encode URI parameters. Also, you are unnecessarily using regexes. Also, you are not HTML encoding your URI.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.