{"id":229,"date":"2009-02-10T20:09:00","date_gmt":"2009-02-10T20:09:00","guid":{"rendered":"http:\/\/blog.trungson.com\/?p=229"},"modified":"2009-02-10T20:09:00","modified_gmt":"2009-02-10T20:09:00","slug":"compact-js-code-using-php","status":"publish","type":"post","link":"http:\/\/blog.trungson.com\/?p=229","title":{"rendered":"Compact JS code using PHP"},"content":{"rendered":"<p>This is a simple function to minimize JS code, it&#8217;s very simple and probably fail with more complex cases. But hey, might be useful for someone for something! We would suggest using JSMin::minify() instead.<\/p>\n<p><textarea name=\"code\" class=\"php\"><br \/>\n\/** compact JS code *\/<br \/>\n function compactJS($pContent) {<br \/>\n  $pContent = str_replace(&#8220;\\r\\n&#8221;,&#8221;\\n&#8221;,$pContent);<br \/>\n  $pContent = preg_replace(&#8220;\/^\\\/\\\/.*\/&#8221;,&#8221;,$pContent); \/\/ begining w\/ \/\/<br \/>\n  $pContent = preg_replace(&#8220;\/[^:]\\\/\\\/.*\/&#8221;,&#8221;,$pContent); \/\/ not those http:\/\/<br \/>\n  $pContent = str_replace(&#8220;\\t&#8221;,&#8221;,$pContent);<br \/>\n  $pContent = str_replace(&#8220;\\n&#8221;,&#8221;,$pContent);<br \/>\n  $pContent = preg_replace(&#8220;\/\\s+\/&#8221;,&#8217; &#8216;,$pContent);<br \/>\n  $pContent = preg_replace(&#8216;\/\\s?([\\{\\};\\=\\(\\)\\\/\\+\\*-])\\s?\/&#8217;,&#8221;\\\\1&#8243;,$pContent);<br \/>\n  return $pContent;<br \/>\n }<br \/>\n<\/textarea><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a simple function to minimize JS code, it&#8217;s very simple and probably fail with more complex cases. But hey, might be useful for someone for something! We would suggest using JSMin::minify() instead. \/** compact JS code *\/ function compactJS($pContent) { $pContent = str_replace(&#8220;\\r\\n&#8221;,&#8221;\\n&#8221;,$pContent); $pContent = preg_replace(&#8220;\/^\\\/\\\/.*\/&#8221;,&#8221;,$pContent); \/\/ begining w\/ \/\/ $pContent = preg_replace(&#8220;\/[^:]\\\/\\\/.*\/&#8221;,&#8221;,$pContent); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,8],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/229"}],"collection":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229"}],"version-history":[{"count":0,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}