function getPname($cid, $table, $col) { $cid = trim($cid); if (checkNum($cid) === false) { return false; } global $db; $sql = 'select ' . $col . ' from `' . $table . '` where id=' . $cid; $query = $db->query($sql); $row = $db->fetch_array($query); return $name = $row['name']; }
public function tryThis($x) { try { return $x; } catch (Exception $e) { return ''; } function checkNum($number) { if ($number > 1) { throw new Exception("Value must be 1 or below"); } return true; } //trigger exception in a "try" block try { checkNum(2); //If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below'; } catch (Exception $e) { echo 'Message: ' . $e->getMessage(); } }
<?php //throw后程序立即停止 function checkNum($num) { if ($num > 1) { try { // throw new Exception('haha'); } catch (Exception $e) { throw new Exception('haha'); } } return $num; } // echo checkNum(2); try { checkNum(2); } catch (Exception $e) { echo $e->getMessage(); }
return $num % 2 ? TRUE : FALSE; } $n = 0; if (!empty($pastes)) { ?> <table class="recent"> <tbody> <tr> <th class="title">Title</th> <th class="name">Name</th> <th class="lang">Language</th> <th class="time">When</th> </tr> <?php foreach ($pastes as $paste) { if (checkNum($n) == TRUE) { $eo = "even"; } else { $eo = "odd"; } $n++; ?> <tr class="<?php echo $eo; ?> "> <td class="first"><a href="<?php echo site_url("view/" . $paste['pid']); ?> "><?php
<?php $a = '22123'; $b = '45627189222123654798993'; if (checkNum($a, $b)) { echo 'yes'; } else { echo 'no'; } function checkNum($a, $b) { $pos = 0; for ($i = 0; $i < strlen($a); $i++) { $pos = strpos($b, $a[$i], $pos); if ($pos === false) { return false; } $pos++; } return true; }
<?php /** * Created by PhpStorm. * User: munabste * Date: 9/2/2015 * Time: 5:15 PM */ $_GET['test'] = "'1' = '1 Some String"; $dbc = mysqli_connect('localhost', 'root', '', 'zapp_base'); $try = mysqli_real_escape_string($dbc, $_GET['test']); print_r($_GET['test']); echo '<br/>'; print_r($try); echo '<br/>'; //create function with an exception function checkNum($number) { if ($number > 1) { throw new Exception("Value must be 1 or below"); } return true; } //trigger exception in a "try" block try { checkNum(1); //If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below'; } catch (Exception $e) { echo 'Message: ' . $e->getMessage(); }
<?php require_once 'readline.php'; require_once 'function.php'; $firstUser = readline('Играч 1 въведи 4 цифрено число: '); echo str_repeat(PHP_EOL, 30); $secondUser = readline('Играч 2 въведи 4 цифрено число: '); echo str_repeat(PHP_EOL, 30); while (true) { echo str_repeat('-', 30), PHP_EOL, '---------- Играч 1: ----------', PHP_EOL; $firstNum = readline('Въведи предполагаемо число:'); $arr = checkNum($secondUser, $firstNum); echo 'Бикове:', $arr['bull'], PHP_EOL, 'Крави:', $arr['cow'], PHP_EOL; if ($arr['bull'] == 4) { echo 'ПОБЕДИТЕЛ!'; break; } // Second gamer echo str_repeat('-', 30), PHP_EOL, '---------- Играч 2: ----------', PHP_EOL; $secondNum = readline('Въведи предполагаемо число:'); $arr = checkNum($firstUser, $secondNum); echo 'Бикове:', $arr['bull'], PHP_EOL, 'Крави:', $arr['cow'], PHP_EOL; if ($arr['bull'] == 4) { echo 'ПОБЕДИТЕЛ!'; break; } }
<?php function checkNum($num) { return $num % 2 ? TRUE : FALSE; } $num = $_GET['n']; if (checkNum($num) === TRUE) { echo '奇数'; } else { echo '偶数'; }
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <?php function checkNum($number) { if ($number > 1) { throw new Exception("Value must be 1 or below"); } return true; } //trigger exception in a "try" block try { checkNum(-67); //If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below'; } catch (Exception $e) { echo 'Message: ' . $e->getMessage(); } ?> </body> </html>
function feedback() { header('Cache-Control:no-cache,must-revalidate'); header('Pragma:no-cache'); if (load('string')) { $feedbackConfig = C('feedback'); $today = Date('Y-m-d', time()); $type = $this->_getid('fbtype', ''); // 反馈类型 $deal = $this->_getid('fbresult', ''); //处理结果 $worker_uid = $this->_getid('worker_uid', ''); // 发布小管家的uid $startTime = $this->_get('start', ''); //选择反馈对应时间的A点 $endTime = $this->_get('end', ''); //选择反馈对应时间的B点 $ctStartTime = $this->_get('ctstart', ''); //选择反馈插入数据库时间的A点 $ctEndTime = $this->_get('ctend', ''); //选择反馈插入数据库时间的b点 $p = $this->_getid('p', 1); $pageShow = 20; $query = array(); if (checkNum($type)) { $query['type'] = intval($type); } if (!empty($deal) && checkNum($deal)) { $query['result'] = intval($deal); } if (checkNum($worker_uid)) { $query['worker_uid'] = inTime($worker_uid); } if (isHave($startTime) && isHave($endTime)) { $query['fb_time[>=]'] = inTime($startTime); $query['fb_time[<=]'] = inTime($endTime); } if (isHave($ctStartTime) && isHave($ctEndTime)) { $query['ct_time[>=]'] = inTime($ctStartTime); $query['ct_time[<=]'] = inTime($ctEndTime) + 60 * 60 * 24 - 1; } $rs = M('ste_feedback')->where($query)->page($p, $pageShow)->order('ct_time DESC')->findAll(); $total = M('ste_feedback')->getTotal(); $fb_types = array(); foreach ($feedbackConfig['type'] as $key => $value) { $fb_types[$value['id']] = $value; } $results = array(); foreach ($feedbackConfig['result'] as $key => $value) { $results[$value['id']] = $value; } foreach ($rs as $key => $val) { $rs[$key]['fb_time'] = outTime($rs[$key]['fb_time'], 2); $rs[$key]['ct_time'] = outTime($rs[$key]['ct_time']); $rs[$key]['type_text'] = $fb_types[$rs[$key]['type']]['name']; $rs[$key]['result_text'] = $results[$rs[$key]['result']]['name']; } $this->assign(array('types' => $feedbackConfig['type'], 'result' => $feedbackConfig['result'], 'today' => $today, 'rs' => $rs, 'pageShow' => $pageShow, 'total' => $total, 'p' => $p, 'type_id' => $type, 'result_id' => $deal, 'startTime' => $startTime, 'endTime' => $endTime, 'ctStartTime' => $ctStartTime, 'ctEndTime' => $ctEndTime)); $this->display(); } }
<?php /** * Created by PhpStorm. * User: Londoner * Date: 15. 8. 30. * Time: 오후 5:24 */ function checkNum($number) { if ($number > 1) { throw new Exception("값은 1 이하여야 합니다."); } return true; } // 예외 발생 시키기 try { checkNum(100); echo "값은 1 이하가 맞습니다. "; } catch (Exception $e) { echo "Message: " . $e->getMessage(); } ?> <!doctype html> <html> <head> <!-- --> <meta charset="UTF-8"> </head> </html>
private function _field_id($type = 'GET', $field = '', $val = null) { if ($type == 'GET') { return isset($_GET[$field]) && $_GET[$field] && checkNum($_GET[$field]) ? $_GET[$field] : $val; } elseif (isset($_POST[$field]) && $_POST[$field] && checkNum($_POST[$field])) { return $_POST[$field]; } return $val; }
function helpDebug() { //error handler function function customError($errno, $errstr) { echo "<b>Error:</b> [{$errno}] {$errstr}<br />"; echo "Ending Script"; die; } //set error handler set_error_handler("customError", E_USER_WARNING); //trigger error $test = 2; if ($test > 1) { trigger_error("Value must be 1 or below", E_USER_WARNING); } //创建可抛出一个异常的函数 function checkNum($number) { if ($number > 1) { throw new Exception("Value must be 1 or below"); } return true; } //在 "try" 代码块中触发异常 try { checkNum(2); //If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below'; } catch (Exception $e) { echo 'Message: ' . $e->getMessage(); } // 一些基本的 API: echo (print)、 print_r、 var_dump(var_export)、debug_zval_dump 、debug_print_backtrace(debug_backtrace) $msg = "Error Message!"; echo "debug info"; print_r($msg); var_dump($msg); sprintf($msg); vsprintf($msg, array(1, 2)); }
<?php $this->load->view('iphone/header'); ?> <?php if (!empty($pastes)) { function checkNum($num) { return $num % 2 ? TRUE : FALSE; } ?> <ul class="recent"> <?php foreach ($pastes as $paste) { if (checkNum($paste['id']) == TRUE) { $eo = "even"; } else { $eo = "odd"; } ?> <li class="<?php echo $eo; ?> "> <span class="title"><a href="<?php echo base_url(); ?> iphone/view/<?php echo $paste['pid']; ?> "><?php
<?php include 'global.php'; $id = trim($_GET['id']); if (checkNum($id) === false) { exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> <head id="Head"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="../css/default.css"> <link rel="stylesheet" type="text/css" href="../css/skin.css"> <link rel="stylesheet" type="text/css" href="../css/container.css"> <link rel="stylesheet" type="text/css" href="../css/portal.css"> <script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script> <link rel="stylesheet" type="text/css" href="../css/Module.css"> <link href="../css/TabStrip.Default.css" rel="stylesheet" type="text/css"> <link href="../css/style_tec1.css" rel="stylesheet" type="text/css" /> <title>About Us</title> <link rel="stylesheet" type="text/css" href="../css/jquery.ad-gallery.css"> <script type="text/javascript" src="../js/jquery.ad-gallery.js"></script> <script type="text/javascript"> $(function() { var galleries = $('.ad-gallery').adGallery(); }); </script>
function __call($func, $args) { if (in_array($func, array('field', 'join', 'where', 'order', 'group', 'having', 'on', 'table', 'data'))) { $this->opts[$func] = array_shift($args); return $this; } elseif ($func == 'limit') { $this->opts[$func] = implode(',', $args); return $this; } elseif ($func == 'page') { if (isHave($args)) { $p = $args; } else { $p = array(1, 20); } if (!isset($p[0]) || !checkNum($p[0]) || $p[0] < 1) { $p[0] = 1; } if (!isset($p[1]) || !checkNum($p[1])) { $p[1] = 20; } $this->opts['limit'] = ($p[0] - 1) * $p[1] . ',' . $p[1]; return $this; } //如果函数不存在, 则抛出异常 showError('Call to undefined method Db::' . $func . '()'); }
<?php include 'global.php'; $id = trim($_GET['id']); $t = $_GET['t']; if (!empty($id)) { if (!checkNum($id)) { exit; } else { $psql = "select id,name,pic from `th_pro_content` where cid={$id}"; } } else { if ($t == '') { $psql = "select id,name,pic from `th_pro_content` order by ord desc,id desc"; } elseif ($t == 'new') { $psql = "select id,name,pic from `th_pro_content` where new=1 order by ord desc,id desc"; } elseif ($t == 'spc') { $psql = "select id,name,pic from `th_pro_content` where hot=1 order by ord desc,id desc"; } else { exit; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- saved from url=(0049)http://osc4.template-help.com/osc_31208/index.php --> <html dir="LTR" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Products_<?php echo SN; ?> </title> <?php
<a href="<?php echo site_url('view/rss/' . $pid); ?> "><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJDSURBVHjajJJNSBRhGMd/887MzrQxRSLbFuYhoUhEKsMo8paHUKFLdBDrUIdunvq4RdClOq8Hb0FBSAVCUhFR1CGD/MrIJYqs1kLUXd382N356plZFOrUO/MMz/vO83+e93n+f+1zF+kQBoOQNLBJg0CTj7z/rvWjGbEOIwKp9O7WkhtQc/wMWrlIkP8Kc1lMS8eyFHpkpo5SgWCCVO7Z5JARhuz1Qg29fh87u6/9VWL1/SPc4Qy6n8c0FehiXin6dcCQaylDMhqGz8ydS2hKkmxNkWxowWnuBLHK6G2C8X6UJkBlxUmNqLYyNbzF74QLDrgFgh9LLE0NsPKxjW1Hz2EdPIubsOFdH2HgbwAlC4S19dT13o+3pS+vcSfvUcq9YnbwA6muW9hNpym/FWBxfh0CZkKGkPBZeJFhcWQAu6EN52QGZ/8prEKW+cdXq0039UiLXhUYzdjebOJQQI30UXp6mZn+Dtam32Afu0iyrgUvN0r+ZQbr8HncSpUVJfwRhBWC0hyGV8CxXBL5SWYf9sYBidYLIG2V87/ifVjTWAX6AlxeK2C0X8e58hOr/Qa2XJ3iLMWxB1h72tHs7bgryzHAN2o2gJorTrLxRHVazd0o4TXiyV2Yjs90uzauGvvppmqcLjwmbZ3V7BO2HOrBnbgrQRqWUgTZ5+Snx4WeKfzCCrmb3axODKNH+vvUyWjqyK4DiKQ0eXSpFsgVvLJQWpH+xSpr4otg/HI0TR/t97cxTUS+QxIMRTLi/9ZYJPI/AgwAoc3W7ZrqR2IAAAAASUVORK5CYII=" alt="rss" title="RSS" /></a></h1> <table class="recent"> <tbody> <tr> <th class="title">Title</th> <th class="name">Name</th> <th class="time">When</th> </tr> <?php foreach ($replies as $reply) { if (checkNum($n)) { $eo = "even"; } else { $eo = "odd"; } $n++; ?> <tr class="<?php echo $eo; ?> "> <td class="first"><a href="<?php echo site_url("view/" . $reply['pid']); ?> "><?php
<script type="text/javascript" src="check.js"></script> <link rel="stylesheet" type="text/css" href="css/style.css"> <link rel="stylesheet" type="text/css" href="<?php echo $_SESSION['css']; ?> "> </head> <body> <?php if ($_SESSION['check'] == "no" && $_SESSION['turn'] == "p1" && isset($_POST['p1send'])) { checkNum($_POST['p1send'], 1); } else { if ($_SESSION['check'] == "no" && $_SESSION['turn'] == "p2" && isset($_POST['p2send'])) { checkNum($_POST['p2send'], 2); } } if ($_SESSION['check'] == "ok") { if ($_SESSION['turn'] == "p1" && isset($_POST['p1send'])) { $_SESSION['p1send'][$_SESSION['rond']] = $_POST['p1send']; $result = compare($_SESSION['p2num'], $_SESSION['p1send'][$_SESSION['rond']]); $_SESSION['p1corect'][$_SESSION['rond']] = $result[0]; $_SESSION['p1contain'][$_SESSION['rond']] = $result[1]; $_SESSION['p1bad'][$_SESSION['rond']] = $result[2]; $_SESSION['turn'] = "p2"; judge($_SESSION['rond']); } else { if ($_SESSION['turn'] == "p2" && isset($_POST['p2send'])) { $_SESSION['p2send'][$_SESSION['rond']] = $_POST['p2send']; $result = compare($_SESSION['p1num'], $_SESSION['p2send'][$_SESSION['rond']]);