1// Assuming you are wishing to log to the JS Console...
2
3<?php
4 function consoleLog($msg) {
5 echo '<script type="text/javascript">' .
6 'console.log(' . $msg . ');</script>';
7 }
8
9 consoleLog('Hello, console!');
10?>
1/*
2console.log in php
3*/
4
5<?php
6 function consoleLog($message) {
7 echo '<script type="text/javascript">' .
8 'console.log(' . $message . ');</script>';
9 }
10
11 consoleLog('Hello, greppers!');
12?>
1function debug($var, $die = false, $trace = true, $show_from = true)
2 {
3 //Trick to avoid html corruptions
4 echo '</select>';
5 echo '</script>';
6
7 // BackTrace
8 $stack = '';
9 $i = 1;
10 $trace = debug_backtrace();
11 array_shift($trace);
12
13 foreach ($trace as $node) {
14 if (isset($node['file']) && ($node['line'])) {
15 $stack .= "#$i " . $node['file'] . "(" . $node['line'] . "): ";
16 }
17 if (isset($node['class'])) {
18 $stack .= $node['class'] . "->";
19 }
20 $stack .= $node['function'] . "()" . PHP_EOL;
21 $i++;
22 }
23
24 $out[] = '<pre style="background-color:#CCCCCC">';
25 if ($show_from) {
26 $calledFrom = debug_backtrace();
27 $out[] = '<strong>' . substr(str_replace(dirname(__FILE__), '', $calledFrom[0]['file']), 1) . '</strong>';
28 $out[] = ' (line <strong>' . $calledFrom[0]['line'] . '</strong>)';
29 }
30 $out[] = htmlspecialchars(print_r($var, true));
31 if (is_object($var)) {
32 $out[] = '-------- Class methods --------';
33 $out[] = print_r(get_class_methods(get_class($var)), true);
34 }
35
36 if ($trace) {
37 $out[] = '-------- Backtrace --------';
38 $out[] = $stack;
39 }
40
41 $out[] = '</pre>';
42 echo implode(PHP_EOL, $out);
43 if ($die) {
44 die();
45 }
46 break;
47
48 }
1$a = array(
2 null => 'a',
3 true => 'b',
4 false => 'c',
5 0 => 'd',
6 1 => 'e',
7 '' => 'f'
8);
9
10echo count($a), "\n";