fork(4) download
  1. <?php
  2.  
  3. $json_origen = <<<'JSON'
  4. {
  5. //Remove this comment
  6. "Command": "storeSystemConfig",
  7. "SystemId": "1234", //Remove this comment
  8.  
  9. /*Remove this and the empty line above and below*/
  10.  
  11. /*This can be removed but not what behind here =>*/"TestParam": "Hello",
  12.  
  13. "TestString": "Do not revome this comment /*don not remove*/ and also this one: //Test comment"
  14. }
  15. JSON;
  16.  
  17. //Remove comment
  18. $json = preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $json_origen);
  19. //Remove empty lines
  20. $json = preg_replace('/\n\s*\n/', "\n", $json);
  21.  
  22. var_dump($json);
  23.  
  24. ?>
Success #stdin #stdout 0.02s 24544KB
stdin
Standard input is empty
stdout
string(144) "{
	"Command": "storeSystemConfig",
	"SystemId": "1234",
	"TestParam": "Hello",
	"TestString": "Do not revome this comment  and also this one:
} "