function dhead($head, $var) { echo '<div class="debug-box">'; echo '================'; echo ' ' . $head . ' '; echo '================'; echo '<br>'; da($var); echo '</div>'; }
public function graph($opts = false) { $debug = false; if (is_array($opts)) { extract($opts); } if (!$view) { $view = "weekly"; } if (!$this->tbl) { $this->tbl = $this->_loadTableInfo(); // $this->tbl = self::$_tableInfo[$this->_table]; } if (!$title) { $title = $this->_table; } if ($debug) { da($this->tbl); } if (!$this->_dateField) { // @todo, infer datefield from field info. JB 8/8/08 2:59 PM $errors[] = "We don't know the date field for {$this->_table}."; } if ($errors) { show_errors($errors); } $g = group_time($view, $this->_dateField, array("table" => $this->_table)); $sql = $this->getTrendSql($opts); $trend = acqueryz($sql, $this->_db); $trend = $trend->fetchAll(); $hidefields = array(); $graphf = array($this->_dateField, 'count'); $data = array(); $i = 0; if (count($trend)) { ?> <div id="tableWrapper" style="display:none"> <div>Showing <b><?php echo $num; ?> </b> records</div> <table class="list"><?php foreach ($trend as $row) { $i++; $i % 2 ? $row_class = "odd" : ($row_class = "even"); extract($row); if ($i == 1) { // do header row ?> <tr class="reverse"> <td>Action</td> <?php foreach ($row as $f => $v) { if (!in_array($f, $hidefields)) { ?> <td><?php echo camelcap($f); ?> </td> <?php } } ?> </tr> <?php } ?> <tr class="<?php echo $row_class; ?> "> <td> <a href="<?php echo $this->_controller; ?> ?action=edit_<?php echo $this->_table; ?> &<?php echo $this->_idField; ?> =<?php echo ${$this}->_idField; ?> ">Edit</a> </td> <?php foreach ($row as $f => $v) { if (!in_array($f, $hidefields)) { if ($f == $graphf[0]) { $v = date($g[dformat], strtotime($v)); $data[$i - 1][label] = $v; } if ($f == $graphf[1]) { $data[$i - 1][point] = $v; } ?> <td> <?php echo $v; ?> </td> <?php } ?> <?php } ?> </tr> <?php } ?> </table> </div> <?php if (count($data)) { $g = new ACGraph($data, $title . " " . $view); $g->render(); } } else { ?> <p>No <?php echo $title; ?> records found</p><?php } }
public function test() { $this->load->library('unit_test'); $this->test_utility_helper(); $this->test_news(); $results = $this->unit->result(); foreach ($results as $result) { if ($result['Result'] == 'Failed') { da($result); } } echo $this->unit->report(); }
[expect php] [file] <?php function da($a) { foreach ($a as $k => $v) { echo "{$k} => {$v}\n"; } } echo str_replace("", "as", "asxas"), "\n"; $a = array("aLEP", "be", "th", "mm"); $b = array("bet", "he", "he"); $c = array("aleph", "beth", "gimmel"); da(str_ireplace($a, $b, $c)); $a = array("aLEP", "be", "th", "mm"); $b = array("bet", "he", "he"); $c = array("aleph", "beth", "gimmel"); da(str_replace($a, $b, $c)); da(str_ireplace(array('*', 'SELECT ', 'UPDATE ', 'DELETE ', 'INSERT ', 'INTO', 'VALUES', 'FROM', 'LEFT', 'JOIN', 'WHERE', 'LIMIT', 'ORDER BY', 'AND', 'OR ', 'DESC', 'ASC', 'ON '), array("<FONT COLOR='#FF6600'><B>*</B></FONT>", "<FONT COLOR='#00AA00'><B>SELECT</B> </FONT>", "<FONT COLOR='#00AA00'><B>UPDATE</B> </FONT>", "<FONT COLOR='#00AA00'><B>DELETE</B> </FONT>", "<FONT COLOR='#00AA00'><B>INSERT</B> </FONT>", "<FONT COLOR='#00AA00'><B>INTO</B></FONT>", "<FONT COLOR='#00AA00'><B>VALUES</B></FONT>", "<FONT COLOR='#00AA00'><B>FROM</B></FONT>", "<FONT COLOR='#00CC00'><B>LEFT</B></FONT>", "<FONT COLOR='#00CC00'><B>JOIN</B></FONT>", "<FONT COLOR='#00AA00'><B>WHERE</B></FONT>", "<FONT COLOR='#AA0000'><B>LIMIT</B></FONT>", "<FONT COLOR='#00AA00'><B>ORDER BY</B></FONT>", "<FONT COLOR='#0000AA'><B>AND</B></FONT>", "<FONT COLOR='#0000AA'><B>OR</B> </FONT>", "<FONT COLOR='#0000AA'><B>DESC</B></FONT>", "<FONT COLOR='#0000AA'><B>ASC</B></FONT>", "<FONT COLOR='#00DD00'><B>ON</B> </FONT>"), array("Select * from adsad where asdasdasda order by by order by limit 21 on asc descwhere", "select from upsdateinsertasc delete join axax"), $count)); echo $count, "\n"; echo bin2hex(str_ireplace("\r\n", "-", "\r\nhell\r\n\r\n\r\no\r\nw\r\n", $c1)); echo bin2hex(str_replace("\r\n", "-", "h\r\nel\r\nlow\r\r\n\r\n\n", $c2)); echo $c1, "-", $c2;
/** * Debug Function * gibt ein Array in Tabbelarischer Form aus. * * @param Array $TheArray * @return mixed */ function da($TheArray) { // Note: the function is recursive if (!is_array($TheArray)) { return "no array"; } echo "<table border=0>\n"; $Keys = array_keys($TheArray); foreach ($Keys as $OneKey) { echo "<tr>\n"; echo "<td bgcolor='#727450'>"; echo "<B>" . $OneKey . "</B>"; echo "</td>\n"; echo "<td bgcolor='#C4C2A6'>"; if (is_array($TheArray[$OneKey])) { da($TheArray[$OneKey]); } else { echo $TheArray[$OneKey]; } echo "</td>\n"; echo "</tr>\n"; } echo "</table>\n"; }
function depr_notify($msg, $realm = 'note') { $CI =& get_instance(); $CI->load->library('session'); da($CI); $notifications = $CI->session->flashdata('flash_notifications'); if (!$notifications) { $notifications = array("{$realm}" => array()); } //da($notifications); $notifications[$realm][] = $msg; $CI->session->set_flashdata('flash_notifications', $notifications); }
[expect php] [file] <?php function da($a) { foreach ($a as $k => $v) { echo "{$k} => {$v}\n"; } } // 8 combinations of possible str_replace arguments: $arr1 = array("a" => "hello", "b" => "world", "c" => "earth", "d" => "europe", "e" => "africa", "f" => "america", "g" => "asia", "h" => "eheheheheheijijijijijlololololo", "i" => "klpofklpofklpof", "j" => "www", "k" => "lo", "l" => "as", "m" => "ing", "n" => "y", "o" => "string"); $arr2 = array("h" => "eheheheheheijijijijijlololololo", "i" => "klpofklpofklpof", "j" => "www", "k" => "lo", "l" => "as", "m" => "ing", "n" => "y"); $str = "hello, very long string with several substrings to be replaced or removed"; echo str_replace(array("hello", "string", "very", "long"), array("XXX"), $str), "\n"; // replace only the first needle with XXX echo str_replace(array("hello", "string", "very", "long"), "XXX", $str), "\n"; // replace all the needles with the same replacement echo str_replace("", "eh, nothing will happen", $str), "\n"; echo str_replace("ing", "", $str), "\n"; //echo str_replace("remo",$arr1,$str),"\n"; echo str_replace($arr2, $arr1, $str), "\n"; echo str_replace($arr1, $arr2, $str), "\n"; echo str_replace($arr1, "some replacement", $str), "\n"; da(str_replace("", "eh, nothing will happen", $arr1)); da(str_replace("ing", "", $arr2)); //da( str_replace("remo",$arr1,$arr1) ); da(str_replace($arr2, $arr1, $arr2)); da(str_replace($arr1, $arr2, $arr1)); da(str_replace($arr1, "some replacement", $arr2));
public function show() { da($this); }
public function save() { $debug = false; $changed_fields = array(); $table_fields = $this->getTableFields(); if ($this->debug) { da($table_fields); } foreach ($table_fields as $k) { if ($k == $this->_idField) { continue; } if ($k == $this->_timeStampField) { continue; } $v = $this->getField($k); // Be smart about dates. JB 10/8/08 4:48 PM if ($debug) { da("hello {$k}"); } if (!self::$_tableInfo[$this->_table][$k]) { self::$_tableInfo[$this->_table][$k] = $this->loadTable(); // da(self::$_tableInfo[$this->_table]); } $field_type = self::$_tableInfo[$this->_db . "." . $this->_table][$k]['type']; if (($field_type == "datetime" || $field_type == "date") && $this->_dbValues[$k] != $v) { $tmp_date = $v; if (trim($v)) { // Fix for some time situations that confuse strtotime $tparts = explode(" ", $v); if (is_array($tparts)) { if (strtolower($tparts[2]) == "pm") { if (substr($tparts[1], 0, 2) > 12) { $v = str_replace("pm", "", $v); } } } $timestamp = strtotime($v); $v = date("Y-m-d H:i:s", $timestamp); $this->{$k} = $v; } if ($debug) { da("This is a date: {$tmp_date} : {$v} "); } } if ($this->_dbValues[$k] != $v) { $changed_fields[$k] = $v; } } $is_update = 0; // deal with index fields if (is_string($this->_idField)) { $idf = $this->_idField; if ($id = $this->{$idf}) { if ($this->isId($id)) { if ($this->exists($id)) { $is_update = 1; } else { // add id to fields to insert $had_id = 1; $changed_fields[$idf] = $id; } } // if there's no id, we just hope for having an id from auto_increment $sql_where = " `{$idf}` = '{$id}' "; } } elseif (is_array($this->_idField)) { unset($sql_set); foreach ($this->_idField as $field) { $sql_set[] = " {$field} = '{$this->{$field}}' "; } $sql_where = implode(" AND ", $sql_set); } // Don't do the query if we don't seem to have anything new to save. if (empty($changed_fields) && !is_update) { // When creating a new record it is legitimate to not set any fields. if ($this->debug) { show_errors("There were no fields to change."); } return false; } else { if ($this->debug) { da($changed_fields); } } $ss = $this->_setstr($changed_fields); $set_sql = "{$ss}"; if (!$set_sql) { // apparently, nothing has changed. return false; } if ($is_update) { $sql = "UPDATE {$this->_table} SET {$set_sql} WHERE {$sql_where} LIMIT 1"; } else { $sql = "INSERT INTO {$this->_table} SET {$set_sql} "; // the following isn't implemented yet. JB 5/28/08 8:21 AM $sql .= " ON DUPLICATE KEY UPDATE {$set_sql}"; } $this->last_sql = $sql; if ($this->debug) { echo "SQL: {$sql}\n"; } $ok = mysql_db_query($this->_db, $sql); if ($this->debug) { da($sql); } if (!$ok) { mysql_die($sql); return false; } else { if (!$is_update and !$had_id) { $id = mysql_insert_id(); } $this->loadFields($id); return $id; } }
function da($array) { foreach ($array as $key => $el) { if (is_array($el)) { da($el); } else { echo "<h4>{$key}</h4>"; highlight_string($el); echo "<hr>"; } } }