Recent Notes
Displaying keyword search results 1 - 10
Created by James on February 02, 2012 09:20:22
Last update: February 02, 2012 09:20:22
This example came from the jQuery validation documentation. The required rule can be used to validate a required selection box when you set the value of the first option to empty.
<!DOCTYPE HTML>
<html>
<head>
<scrip...
The error message is the title since no error message is specified. A more fully defined validation check would look like this:
$('#my-form').validate({
errorElement: "p",
...
Created by James on January 26, 2012 21:23:56
Last update: January 26, 2012 21:23:56
In an HTML page, elements can overlap because of position styles. When there's an overlap, elements coming later in the HTML code are displayed on the top. This can be altered by specifying z-index in the CSS. Elements with higher z-index are placed on the top.
However , z-index only works for elements that are not static positioned. Static positioned elements are always at the bottom compared to relative , fixed and absolute positioned elements.
This is a test page:
<!DOCTYPE html>
<html>
<head>
<style t...
Effects of z-index can be tested by adding it to the elements, for example:
<div id="bg" class="big" style="z-index: 3"></div>...
Created by Fang on December 05, 2011 08:41:31
Last update: December 05, 2011 08:41:31
Behavior for functions substringBefore and substringAfter are well defined when the string to look for exists. But what happens when the substring is not found? Do they return the whole string or empty string?
Code:
<p>substringBefore('a.b', '.'): #{fn:substringBefo...
Result:
substringBefore('a.b', '.'): a
substringBef...
Created by magnum on October 06, 2011 14:35:20
Last update: October 06, 2011 14:35:20
The longjmp function jumps to the line where setjmp was last called. In return, setjmp returns the value passed in as the second parameter to longjmp .
#include <stdio.h>
#include <stdlib.h>
#incl...
Result:
$ ./longjmp
val is 0
val is 1
--> val is ...
Created by jinx on May 03, 2011 08:56:55
Last update: May 03, 2011 08:57:54
These error level constants are defined in PHP : Constant Value Description E_ERROR 1 Fatal run-time errors. Execution of the script is halted. E_WARNING 2 (1<<1) Run-time warnings (non-fatal errors). Execution of the script is not halted. E_PARSE 4 (1<<2) Compile-time parse errors. Parse errors should only be generated by the parser. E_NOTICE 8 (1<<3) Notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. E_CORE_ERROR 16 (1<<4) Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP. E_CORE_WARNING 32 (1<<5) Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated...
Created by James on May 01, 2011 21:40:35
Last update: May 01, 2011 21:47:18
It's a shame that double click events are always accompanied by click events in JavaScript. When you double click on an element, JavaScript fires two click events followed by one double click event. So if you attach both click and double click event handlers to the same element, both event handlers will be called when you double click. This is a utility function to alleviate the problem somewhat:
<!doctype html> <html> <head> <script ... Note that there's still a possibility that both clicks and double clicks fired at the same time. This is because the timer used above may not be identical to the double click timer configured at the OS level. It's impossible to fix this problem in application code since each user may...
Created by jinx on April 29, 2011 13:43:13
Last update: April 29, 2011 13:44:34
List of functions testing variable type:
Function Description
is_bool Finds out whether a variable is a boolean
is_double Alias of is_float()
is_float Finds whether the type of a variable is float
is_int Find whether the type of a variable is integer
is_integer Alias of is_int()
is_long Alias of is_int()
is_null Finds whether a variable is NULL
is_numeric Finds whether a variable is a number or a numeric string
is_object Finds whether a variable is an object
is_real Alias of is_float()
is_scalar Finds whether a variable is a scalar
is_string Find whether the type of a variable is string
Test code:
<?php
class A {
}
$a = ar...
Output:
var_dump: int(1)
-------------------------
i...
Created by jinx on April 25, 2011 12:43:40
Last update: April 25, 2011 12:43:40
Use the PHP function method_exists to check if the class or object has a certain method. It returns TRUE if the method exists (even when the value of the property is NULL), FALSE if the method does not exist.
Example:
<?php
class A {
var $p = 'A property';
...
Outputs:
Class A has method f1: bool(true)
Object $a has...
Also note that C++-like method overloading does not exist in PHP. Thus there's no ambiguity about which version of the method exists, i.e., with no argument, with one argument... etc. The following code generates Fatal error:
<?php
class A {
var $p = 'A property';
...
Created by jinx on April 16, 2011 14:33:05
Last update: April 16, 2011 14:34:26
The PHP function implode joins array elements with a string and returns a string gluing together all elements.
join is an alias of implode .
Example:
<?php
$a = array("red", "green", "blue");
ec...
Prints:
Three primary colors: red, green, blue
Three pr...
Created by jinx on April 10, 2011 21:15:46
Last update: April 10, 2011 21:23:04
When developing in PHP, it's frustrating to have errors in the code but no error message displays. According to the PHP manual, the display_errors setting controls whether errors are displayed. You can either change it in php.ini :
; This directive controls whether or not and where...
or set it in your code:
<?php
ini_set('display_errors', 'On');
fsdlf...
But when you have syntax errors in your code, the ini_set function may not even get a chance to execute. So the only reliable way is to set it in php.ini :
<?php
// nothing gets displayed when display_er...