Category: php

  • Compact JS code using PHP

    This is a simple function to minimize JS code, it’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(“\r\n”,”\n”,$pContent); $pContent = preg_replace(“/^\/\/.*/”,”,$pContent); // begining w/ // $pContent = preg_replace(“/[^:]\/\/.*/”,”,$pContent);…

  • CakePHP – Simple User Registration

    After doing some initial readings on different PHP frameworks, including CakePHP, CodeIgniter, Symphony, Zend. I’m digging deeper into CakePHP with an open eyes for fresh ideas and other developments. To start, CakePHP is slow, quite slow (backed up by Rasmus’s benchmark at froscon). It also has not taken advantage of more object-oriented syntax and methods.…

  • Improve security for apc.php

    If you’re running APC with PHP, you have the option to download apc.php to view, monitor the usage/stats. However, the default authentication is very open. Without any credential, anyone can view the running stats and also the cached filenames (a simple search on “APC INFO” will show some site running APC). The login is to…

  • Linear Regression PHP Class

    This PHP 5 class accepts an array of data as input, performs linear regression analysis and returns the trend line. The result is the same as in Excel (Tools/Data Analysis/Regression) Sample Usage // sales data for the last 30 quarters $vSales = array( 637381,700986,641305,660285,604474,565316,598734,688690,723406,697358, 669910,605636,526655,555165,625800,579405,588317,634433,628443,570597, 662584,763516,742150,703209,669883,586504,489240,648875,692212,586509 ); $vRegression = new CRegressionLinear($vSales); $vNextQuarter = $vRegression->predict(); //…