JavaScript Minifier PHP Example

Check the example on how to use
PHP
to minify a JavaScript hardcoded string and output to stdout:
<?php
    $url = 'https://www.toptal.com/developers/javascript-minifier/api/raw';

    // init the request, set various options, and send it
    $ch = curl_init();

    curl_setopt_array($ch, [
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => ["Content-Type: application/x-www-form-urlencoded"],
        CURLOPT_POSTFIELDS => http_build_query([ "input" => "console.log(  1  )" ])
    ]);

    $minified = curl_exec($ch);

    // finally, close the request
    curl_close($ch);

    // output the $minified JavaScript
    echo $minified;
?>
Save the code to a file named
minify.php
and run the following command:
php minify.php

Output:

console.log(1)