Tuesday, May 5, 2015

Home Coding php mysql css javascript jQuery open source tools Apache Node.js WordPress Typo3 OpenSS


Home Coding php mysql css javascript jQuery open source tools Apache Node.js WordPress Typo3 OpenSSL Piwik Jenkins Selenium virtualbox xampp oxide online tools scrum Continous Integration Imprint
The W3C Validator is already known on the Internet and is used many thousand times to site to check on a daily basis HTML conformity. The online tool provides several options for this testing be carried out, including an API. Around this API can also be found quickly a few wrapper scripts to facilitate the handling of it. I've looked at a few and I could not find a simple PHP script that only hinschickt a specific URL to W3C Validator and entgegenimmt the result. Something like this as you know from the Validator plugin from Firefox. Just click and read result, pre-configure anything or initialize.
Since I have found no meaningful script for my needs, I wrote a short hand its own. This PHP script I use in connection with Jenkinis flv and validate flv during the Deploy process the websites of the respective Web project. This ensures that with each Deploy valid HTML is delivered.
Quite simply the matter was not because of the service of the W3C Validator is not necessarily stable available. Therefore, the script checks every URL often, to a reasonable return from the W3C Validator returns. But I assume when the W3C Validator 3 times consecutively nothing vernüftiges returns, he is simply not available, and the test can not be carried out in general.
/ * Setting infinite time limit for the scripts, test can run a long time * / set_time_limit (0); / * Define the url you like to check * / $ checkURL = array ('http: //mytesthost/index.php "," http: //mytesthost/impressum.php/ "); foreach ($ checkURL as $ url) {$ HTTP_STATUS = "0"; $ I = 0; while (! $ HTTP_STATUS = '200') {/ * Fake the browser type * / ini_set ('user_agent', 'MSIE 4 \ .0b2;'); / * Read the respond into a result flv * / $ result = file_get_contents ($ url); / * If there is no result of the test page * / if (empty ($ result)) {echo "The check url can't be open:". $ CheckURL; flv clean_up (); exit (1); } Else {file_put_contents ('tmp.html', $ result); } / * Take a Break, as the WC3 Validator can recover * / sleep (20); / * Setting the vars for the W3C Validator * / $ target_url = 'http://validator.w3.org/check?output=soap12&outline&uploaded_file'; $ File_name_with_full_path = realpath ('tmp.html'); $ Post = array ('extra_info' = & gt; '123456', 'uploaded_file' = & gt; '@' $ file_name_with_full_path.. "; Type = text / html"); / * All the curl operation * / $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_USERAGENT, 'MSIE 4 \ .0b2;'); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_VERBOSE, 1); curl_setopt ($ ch, CURLOPT_HEADER, 1); curl_setopt ($ ch, CURLOPT_URL, $ target_url); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post); $ Result = curl_exec ($ ch); $ HTTP_STATUS = curl_getinfo flv ($ ch, CURLINFO_HTTP_CODE); curl_close ($ ch); / * Checking the respond of the W3C Validator it turns our very Often a 500, so we try again * / if ($ HTTP_STATUS = '200') {/ * Counting the error Ministries * / $ i ++; } Else {/ * Resetting the error counting * / $ i = 0; / * Pealing the HTTPS headers from the validator * / / * status VALID or INVALID * / $ pos = strrpos ($ result, "X-W3C flv validator status"); if (! $ pos = 0) {$ status = substr ($ result, $ pos + 23, 8); $ Status = trim ($ status, ""); } / * Number of Errors * / $ pos = strrpos ($ result, "X-W3C Validator flv Errors:"); if (! $ pos = 0) {$ errors = substr ($ result, $ pos + 23, 4); } / * Number of Warnings * / $ pos = strrpos ($ result, "X-W3C validator warnings:"); if (! $ pos = 0) {$ WARNINGS = substr ($ result, $ pos + 25, 4); } / * Checking the result and setting exitCode * / if (strtoupper ($ status) == "INVALID") {echo "site:". $ Url. ""; echo "NUMBER OF WARNINGS HTML". $ WARNINGS. ""; echo "NUMBER OF ERRORS HTML". $ Errors. ""; clean_up (); exit (1); }} / * If we tried it three times in a row and always error then exit * / if ($ i == 3

No comments:

Post a Comment