-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path008-debug.php
59 lines (44 loc) · 1.03 KB
/
008-debug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* DEBUG UTILITY FUNCTION
* ======================
*
* This is a classic debug utility that you can include as
* library in your scripts.
*/
function debug($var = false, $showHtml = false) {
print "\n<pre class=\"cake_debug\">\n";
ob_start();
print_r($var);
$var = ob_get_clean();
if ($showHtml) {
$var = str_replace('<', '<', str_replace('>', '>', $var));
}
print "{$var}\n</pre>\n";
};
// debug a string
$foo = 'I am a string';
debug($foo);
// debug a number
$foo = 123;
debug($foo);
// debug a boolean
$foo = true;
debug($foo);
// debug an array
$foo = Array('apple','orange','pear');
debug($foo);
// debug an array position
debug($foo[1]);
// debug an associative array:
$foo = Array(
'name' => 'Marco',
'surname' => 'Peg'
);
debug($foo);
// debug an associative array position:
debug($foo['name']);
// debug an html string
debug('<p>My name is <b>Marco Peg</b>.</p>');
// debug an html string showing it's code
debug('<p>My name is <b>Marco Peg</b>.</p>', true);