0

Hi everyone i have a Php function which use JSMin to Minify JavaScript but i want a regex to replace long arguments name with a or b

function foo(long_arg_name, long_arg_name2){ alert(long_arg_name + long_arg_name); }

to

function foo(a,b){ alert(a+b); }

1
  • You don't always get what you want. Commented Sep 20, 2014 at 12:36

1 Answer 1

1

You can use this plugin:

https://github.com/promatik/PHP-JS-CSS-Minifier

It uses this minifier http://javascript-minifier.com/

Or use this script from http://javascript-minifier.com/examples

<?php
    // setup the URL, the JS and the form data
    $url = 'http://javascript-minifier.com/raw';
    $js = file_get_contents('./public/ready.js');
    $data = array(
        'input' => $js
    );

    // init the request, set some info, send it and finally close it
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $minified = curl_exec($ch);

    curl_close($ch);

    // output the $minified
    echo $minified;
?>

Don't forget to cache everything :)

Sign up to request clarification or add additional context in comments.

1 Comment

Hi there :) Are you already use the same minifier ? I try to use it by with this solution i get // input was empty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.