Everyone knows that at the moment’s internet browser has an excellent console logging mechanism which I’ve used to create a easy and really useful PHP class for displaying variable, arrays values on browser console through the use of javascript. This straightforward PHP class has 4 hint ranges data, warn, log, error which developer can use to show variable, arrays values on browser console.
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
|
/****************************************************************
* Class used to log worth of variable, array on Browser console.
* creator: Tousif Khan
****************************************************************/
class WebConsole {
non-public static perform write($information, $sort = ‘data’) {
$method_types = array(‘error’, ‘data’, ‘log’, ‘warn’);
$msg_type = ”;
if(in_array($sort, $method_types)) {
$msg_type = sprintf(“console.%s”, $sort);
}else {
$msg_type = sprintf(“console.%s”, ‘data’);
}
if(is_array($information)) {
echo(“”);
} else {
echo(“”);
}
}
public static perform data($information) {
self::write($information);
}
public static perform error($information) {
self::write($information, ‘error’);
}
public static perform log($information) {
self::write($information, ‘log’);
}
public static perform warn($information) {
self::write($information, ‘warn’);
}
}
?>
|
Now import the WebConsole class and use the tracing capabilities.
1
2
3
4
5
6
7
8
|
require_once(‘WebConsole.php’);
$fruits = array(‘apple’, ‘mange’, ‘banana’);
WebConsole::log($fruits);
WebConsole::data($fruits);
WebConsole::warn($fruits);
WebConsole::error($fruits);
?>
|
Now verify your Internet Browser console. You will see that the out put just like following screenshot.
Supply techzoo.org