Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6073723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:18:09+00:00 2026-05-23T10:18:09+00:00

I have used a PHP version of JSLint for the build script. But I

  • 0

I have used a PHP version of JSLint for the build script. But I didn’t write it.. my ex-coworker did. But now, I can’t remember what the name is, and where can I find that PHP library do to JSLint thing for me. Any know? Thaks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:18:09+00:00Added an answer on May 23, 2026 at 10:18 am

    Try:

    http://www.overflow.biz/blog/lang/en-us/2010/07/07/jslint-php-class/

    With:

    http://www.javascriptlint.com/download.htm

    Code from first link (credit to z3n)

    Solution:

    // (c) z3n - R1V1@100707 - www.overflow.biz - rodrigo.orph@gmail.com
    // Based on the original by Matthias Miller (http://www.JavaScriptLint.com/)
    
    class JSLEngine {
        private $_binarypath;  // jlint exec
        private $_confpath;    // config path
        private $fn;           // temp filename (not used outside class)
        private $r;            // jlint output
        private $has_errors=0; // error flag
    
        public function __construct($binarypath="", $confpath="") {
            // default paths
            base_defines(array(
                "jslint_binary_path" => _fn_fix(dirname(dirname(dirname(__FILE__)))."/3rd/jsl-0.3.0/jsl.exe"),
                "jslint_conf_path" => _fn_fix(dirname(dirname(dirname(__FILE__)))."/3rd/jsl-0.3.0/jsl.default.conf")
            ));
    
            // startup
            $this->_binarypath = $binarypath == "" ? jslint_binary_path : $binarypath;
            $this->_confpath = $confpath == "" ? jslint_conf_path : $confpath;
        }
    
        public function __destruct() {
            if ($this->fn != null && file_exists($this->fn))
                unlink($this->fn);
        }
    
        /* returns error on failure; returns true on success */
        public function Lint($code) {
          if (!$this->_launchLintBinary($code, $output))
              die('The JavaScript Lint online service is currently unavailable.');
    
          // store lint
          $this->r=$output;
          $output=explode("\n",$output); // break lines
          $x=$output[count($output)-2]; // X error(s), X warning(s) (total lines -2)
          $x=trim(substr($x,0,strpos($x," ")));
          if ($x > 0) { // has errors
              $this->has_errors=1;
              return false;
          } else { // clean
              $this->has_errors=0;
              return true;
          }
        }
    
        /* assumes path and that SERVER_SOFTWARE env is set */
        private function _launchLintBinary($input, &$output) {
        $descriptorspec = array(
            0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
            1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
            2 => array("pipe", "w")
        );
    
        $this->fn=_fn_fix(dirname(__FILE__).'/tmp.js');
    
        file_put_contents($this->fn,$input);
        /* launch process */
        $path = PHP_OS == "WINNT" ? $this->_binarypath : escapeshellcmd($this->_binarypath);
        $path.= ' --nologo --conf '.escapeshellarg($this->_confpath).' --process '.escapeshellarg($this->fn);
    
        $process = proc_open($path, $descriptorspec, $pipes);
        if (!is_resource($process))
            return false;
    
        $output = '';
        while (!feof($pipes[1]))
           $output .= fgets($pipes[1], 1024);
        fclose($pipes[1]);
        fclose($pipes[2]);
    
        // It is important that you close any pipes before calling
        // proc_close in order to avoid a deadlock
        $return_value = proc_close($process);
        return true;
        }
    
        public function output() {
            return $this->r;
        }
    }
    

    Helper functions:

    function _fn_fix($fn,$force="") { // v1.02
        if (strpos($fn,"://") === false) {
            if ((PHP_OS == "WINNT" && $force == "") || $force == "WINNT")
                $fn=str_replace("/","\\",$fn);
            else
                $fn=str_replace("\\","/",$fn);
        }
        if (strpos($fn,":/") !== false && strpos($fn,"://") === false)
            $fn=substr($fn,2);
    
        return $fn;
    }
    
    function base_defines($x) { // define default
        foreach ($x as $k => $v) {
            if (!defined($k)) {
                define($k,$v);
            }
        }
    }
    

    Usage:

    $lint=new JSLEngine();
    if (!$lint->Lint($js)) {
        echo "bad js code! full output:\n";
        echo $lint->output();
    }
    

    Required:

    jslint binaries from http://www.JavaScriptLint.com/

    Make sure you set the default path on the __construct, so you don’t need to keep setting it on every call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always used PHP 5.2.3 version, but now I updated PHP to version 5.3.2.
I have used PHP for awhile now and have used it well with CodeIgniter,
I have coded a php script that is used to check the status of
PHP Version 5.2.17 I have the following PHP script for downloading a binary file:
I have recently used a PHP pagination tutorial, Pagination - what it is and
I used to have PHP websites and using url rewriting on picture to have
Sessions in PHP seemed to have changed since the last time I used them,
I am used to developing in PHP/MySQL and have no experience developing with SQL
I have quite a lot of PHP view files, which I used to include
I have used traditional version control systems to maintain source code repositories on past

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.