Recent Notes

Displaying keyword search results 1 - 10
Created by James on January 10, 2011 15:20:10    Last update: February 03, 2012 10:10:14
Dojo ShrinkSafe: http://shrinksafe.dojotoolkit.org/ : command line utility written in Java, based on Rhino - JavaScript engine written in Java. Douglas Crockford's JSMIN: http://crockford.com/javascript/jsmin : command line utility written in C, can download MS-DOS exe. Dean Edwards' Packer: http://dean.edwards.name/packer/ : online tool, or .NET, Perl, PHP application. YUI Compressor: http://developer.yahoo.com/yui/compressor/ : command line utility written in Java. Google Closure Compiler : command line Java application, web application, or RESTful API. One problem is, the compressor utility may not be 100% reliable. So make sure to test the compressed script.
Created by jinx on May 18, 2011 20:09:05    Last update: May 18, 2011 20:09:05
The PHP function file_get_contents reads the entire contents of a file into a string, while the function file reads a file into an array. file_get_contents('filename') is equivalent to implode('', file('filename')) : <?php // reads entire file into array, one elem...
Created by jinx on May 04, 2011 19:39:44    Last update: May 04, 2011 19:42:51
The function include includes the specified file multiple times, while include_once only includes the file once. This is a test: Create file test.php with contents: <?php for ($i = 0; $i < 5; $i++) { inclu... Create file test.inc with contents: <?php echo __FILE__, " included: $i\n"; ?> ... Run test.php , the output is: E:\phpwork\test.inc included: 0 E:\phpwork\test... Change include to include_once , only one line is printed: E:\phpwork\test.inc included: 0 You must use include_once to avoid duplicate includes in the case A includes B and C , but B and C both includes D . The relationship between require and require_once is the same.
Created by jinx on May 03, 2011 09:12:05    Last update: May 03, 2011 09:12:19
Both include and require include and evaluate the file specified as argument. The only difference is, when the included file cannot be found, include emits a warning while require emits a fatal error. Example: <?php include('non-existing-file'); require(... Outputs: PHP Warning: include(non-existing-file): failed t... Suppress error with @ : <?php @include('non-existing-file'); echo "A... Outputs: After include
Created by jinx on May 02, 2011 20:48:49    Last update: May 02, 2011 20:58:01
A PHP try catch block looks like this: <?php try { throw new MyException('foo!'... Normally, no exceptions are thrown from internal function errors. For example: <?php $a = 1; $b = 0; try { $v = $... The division by zero error is never caught as an exception. However , you can translate errors into exceptions with an error handler and ErrorException : <?php function exception_error_handler($errno, ... which prints: Exception: exception 'ErrorException' with message... PHP does not support finally clause.
Created by jinx on April 28, 2011 20:52:45    Last update: April 29, 2011 13:27:31
This is normally a syntax error just before some variable. Try some of these: Missing operator before a variable: <?php $a = 'ab'; echo('Missing conca... Missing semicolon at end of line: <?php echo('Missing semicolon at end of lin... Missing ( and ) in for loop: <?php foreach $a as $i { echo "$i\n"; ... Missing keyword before class variable: <?php class A { // should be var $a; ...
Created by jinx on April 28, 2011 21:09:08    Last update: April 28, 2011 21:09:08
PHP global variables are defined outside of functions and classes. They are visible both in the current file and in any included/required files. Also, any global variables defined in required/included files are visible in the current file. But they are not visible in any functions or classes, unless specifically declared global . Test: Create file test.php : <?php ini_set('display_errors', 'stderr'); i... Create file test.inc : <?php echo '[', __FILE__, '] $a . $b = ', $... Run the PHP script in command line: php test.php 2>C:\tmp\stderr.out The result is: [C:\work\test.inc] $a . $b = ab [C:\work\test.p... stderr messages: PHP Notice: Undefined variable: b in C:\work\scra...
Created by jinx on April 25, 2011 12:57:46    Last update: April 25, 2011 12:58:08
In PHP, a heredoc string starts with <<< followed immediately by an end tag and a new line, and ends by the end tag on its own line followed by a semi-colon. Example: <?php $v = "variable"; $s = <<<END_TAG ...
Created by jinx on April 20, 2011 08:59:07    Last update: April 20, 2011 08:59:30
You get this warning when timezone is not set (which is the default): PHP Warning: mktime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in test.php on line 8 To get rid of the warning message, set timezone in php.ini : ;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;...
Created by jinx on April 19, 2011 20:59:13    Last update: April 19, 2011 21:00:05
To write to a file with PHP (either text or binary): Get a file handle with fopen . Write to the file with fwrite . fwrite writes a string to a file. But since PHP strings are simply arrays of bytes, there's really no difference between text and binary. Close the file with fclose . Example code: <?php $fname = "test.txt"; // wr...
Previous  1 2 Next