I'm using '/\s+/'
switch in preg_replace
to remove all the white spaces from Javascript code, that I pass in PHP array:
preg_replace('/\s+/', '',
("
function(uploader)
{
if(uploader.files.length > 1)
{
uploader.files.splice(1, uploader.files.length);
apprise('You can not update more than one file at once!', {});
}
}
"))
This is for an very basic Javascript minification. In PHP file (source) I can have fully readable function code, while in browser, it page body it ends up like single-line string:
function(uploader,files){console.log('[PluploadUploadComplete]');console.log(files);},'QueueChanged':function(uploader){if(uploader.files.length>1){uploader.files.splice(1,uploader.files.length);apprise('Youcannotupdatemorethanonefileatonce!',{});}}
As you can see (or expect) this does affects strings in quotation marks and produce message without spaces (like: Youcannotupdatemorethanonefileatonce!
).
Is there a workaround for this problem? Can I remove all whitespaces from everywhere in my string, except for part embedded in single quotation marks?