Recent Notes
Displaying keyword search results 91 - 100
Created by jinx on April 16, 2011 15:25:46
Last update: April 16, 2011 15:25:46
The PHP function print_r prints human-readable information about a variable, while the function var_dump dumps information about a variable.
Here's an example:
<?php
$a = array ('a' => 'apple', 'b' => 'banan...
which prints:
Array
(
[a] => apple
[b] => b...
So while print_r is "human readable", var_dump provides more information.
Created by jinx on April 16, 2011 15:03:17
Last update: April 16, 2011 15:03:17
The PHP function str_split splits a string to an array of strings with a max length. So the first n-1 elements will have the max length, the last element will have either the max length or less.
Example:
<?php
$colors = "red, green , ,, blue";
...
Prints:
array(5) {
[0]=>
string(5) "red, "
...
Created by jinx on April 16, 2011 14:56:41
Last update: April 16, 2011 14:56:57
The PHP function preg_split splits a string by a regular expression.
Example:
<?php
// split by comma
$colors = "red, gr...
Prints:
array(3) {
[0]=>
string(3) "red"
[1...
Created by jinx on April 16, 2011 14:46:25
Last update: April 16, 2011 14:46:25
The PHP explode function splits a string by a delimiter string. It is the opposite of implode .
<?php
// split by comma
$colors = "red,green...
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 16, 2011 13:26:22
Last update: April 16, 2011 13:26:22
The function is uksort .
Example:
<?php
$a = array(
"a" => "Apple",
"O" ...
Outputs:
array(4) {
["a"]=>
string(5) "Apple"
...
Created by jinx on April 16, 2011 13:08:50
Last update: April 16, 2011 13:09:13
There are two functions:
int strcasecmp (string $str1 , string $str2) : binary safe case-insensitive string comparison.
int strnatcasecmp (string $str1 , string $str2) : case insensitive string comparisons using a "natural order" algorithm (a comparison algorithm that orders alphanumeric strings in the way a human being would).
In both cases the function returns:
< 0 if str1 is less than str2
= 0 if str1 is equal to str2
> 0 if str1 is greater than str2
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...
Created by jinx on April 10, 2011 20:56:06
Last update: April 10, 2011 20:59:33
The PHP manual says that the count function also counts the properties for an object. Not true. Using count on an object reference always returns 1. In order to count properties, you have to cast the object to an array, which is equivalent to calling get_object_vars on the object. When you cast an object to an array, count is still counting the number of elements in an array!
<?php
class Vegetable {
var $name;
...
Outputs:
array(3) {
["name"]=>
string(7) "Cabbage...
Created by jinx on April 10, 2011 15:56:07
Last update: April 10, 2011 15:56:07
This is a utility function to find a string between two other strings, such as the text between the <title> tags in an HTML header.
<?php
$s = '<html><head><title>Find it!</title>...