W3C home > Mailing lists > Public > www-validator@w3.org > February 2010

simple php validation include that works with allow_url_fopen disabled

From: Jared Crutchfield <jared.crutchfield@wideband.net.au>
Date: Thu, 25 Feb 2010 21:52:56 +1100
To: www-validator@w3.org
Message-Id: <1267095176.3203.14.camel@lilly>

In the interest of open source, here's the contents of a little PHP
include file that I've started using on my website during development.

If you're curious, visit https://cis.biz.tm/ to see its use.

If you find errors, or even things that are "unconventional", please let
me know. I've only been PHP programming for about a year so any advice
is always welcome.

Much of the code is from
so many thanks must go to "gsnedders". I've just wrapped it up a bit

One neat thing about using fsockopen is that it works even with
"allow_url_fopen" disabled in "php.ini.


Jared Crutchfield


# http://www.codingforums.com/archive/index.php/t-79832.html

function IsValidHTML($HTML)
  if (!$fp)
    return False;
    $out="POST /check?;output=xml HTTP/1.0\r\n";
    $out=$out."Host: validator.w3.org\r\n";
    $out=$out."Content-type: application/x-www-form-urlencoded\r\n";
    $out=$out."Content-length: ".(strlen($HTML)+strlen('fragment='))."\r\n";
    $out=$out."Connection: Close\r\n\r\n";
    while (!feof($fp))
    if ($i>0)
      if ($j>0)
        if (strtolower(trim(substr($HTML,$i+strlen($statuskey),$j-$i-strlen($statuskey))))=="valid")
          return True;
  return False;

function GetValidHTMLIcon()
  return "<img src=\"http://www.w3.org/Icons/valid-html401-blue\" alt=\"HTML 4.01 Validated\">\n";

Received on Friday, 26 February 2010 13:49:47 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 1 March 2016 14:18:00 UTC