Mobile app version of vmapp.org
Login or Join
Shelton105

: PHP W3 Validator API, Is this good? 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

@Shelton105

Posted in: #Api #Php #Validation

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 "";
}
}

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Shelton105

1 Comments

Sorted by latest first Latest Oldest Best

 

@Megan663

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme