Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. <?php
  2. $file = isset($argv[1]) ? $argv[1] : null;
  3. if (empty($file)) {
  4. printf("USAGE: %s file.js", $argv[0]);
  5. exit;
  6. }
  7.  
  8. if (!is_file($file)) {
  9. printf("ERROR: File does not exist: %s", $file);
  10. }
  11.  
  12. $content = file_get_contents($file);
  13.  
  14. $content = preg_replace_callback('/`(.*?)`/s', function($groups) {
  15. $value = $groups[1];
  16.  
  17. $value = preg_replace_callback("/(\r?\n)/", function($groups) {
  18. return '\n\\' . $groups[1];
  19. }, $value);
  20.  
  21. $quote = '"';
  22. $value = $quote. addcslashes($value, $quote) . $quote;
  23.  
  24. return $value;
  25. }, $content);
  26.  
  27. file_put_contents($file, $content);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement