随笔分类 - php
摘要:name = $name; } abstract function fire();}class M extends E{ function fire(){ print "{$this->name}:iiiii\n"; }}class N{ private $e = array(); function adde($ename){ $this->e[] = new M($ename); } function p(){ if(count($this->e)>0){ $emp = array...
阅读全文
摘要:好荣幸能够收到淘宝的面试通知,这里整理下php相关的面试题,不管难易,加深下自己的记忆1,post和get传值的区别。主要区别是,get是通过地址栏传值,大小限制在2kb,post一般通过表单传值,默认是不限制数据大小。get传值效率要比post高,但是安全性上post要好很多。Get方式提交的参数及参数值会在地址栏显示,不安全,而Post不会,比较安全2,include和require的去吧。include在处理失败时会发出一个警告,然后程序继续运行,require在失败时会产生致命 错误,程序无法继续执行。3,如何优化mysql数据库对查询比较频繁的字段设置索引;单表数据不要过多,适当的.
阅读全文
摘要:num=$num;$this->price=$price;}publicfunctioncost(){if($this->price==self::Ted)return30;elseif($this->price==self::Sed)return5*$this->num;else{$this->price==self::Ted;return35;}}publicfunctionccc(){if($this->price==self::Ted)return'a';elseif($this->price==self::Sed)return
阅读全文
摘要:<?php//获取tech和98426这两个字符串$str="http://info.meadin.com/tech/98426_1.shtml";echo$newstr=substr($str,7,strlen($str)); //info.meadin.com/tech/98426_1.shtml$arr=explode('/',$newstr);$num = $arr[1];//tech$user=strstr($arr[2],'_',true);//98426
阅读全文
摘要:1, /** * 将一个平面的二维数组按照指定的字段转换为树状结构 * * 用法: * @code php * $rows = array( * array('id' => 1, 'value' => '1-1', 'parent' => 0), * array('id' => 2, 'value' => '2-1', 'parent' => 0), * array('id' => 3, 'value&
阅读全文
摘要:后台:(有点问题 page应该从1开始 而不是从0开始) public function actionExperts() { $top=5; $page=empty($_GET['page']) ? 0 : $_GET['page']; $offset = $top*$page; $result = AboutUs::getExpertsList($top, $offset); if(!$result || count($result) request->isAjaxRequest) { // $this->ajaxRender(array('
阅读全文
摘要:yii index.phpini_set("display_errors", 1);iconv这个函数不能直接用 需要检测!!!function gb2312_utf8($str = ""){ if(function_exists("iconv")){ return iconv("gb2312", "utf-8//IGNORE", $str); }else if(function_exists("mb_convert_encoding")){ return mb_conver
阅读全文
摘要:过滤器官方页面:http://www.yiiframework.com/doc/guide/1.1/zh_cn/basics.controller过滤器是一段代码,可被配置在控制器动作执行之前或之后执行。例如, 访问控制过滤器将被执行以确保在执行请求的动作之前用户已通过身份验证;性能过滤器可用于测量控制器执行所用的时间。一个动作可以有多个过滤器。过滤器执行顺序为它们出现在过滤器列表中的顺序。过滤器可以阻止动作及后面其他过滤器的执行过滤器可以定义为一个控制器类的方法。方法名必须以filter开头。例如,现有的filterAccessControl方法定义了一个名为accessControl的过滤
阅读全文
摘要:public void __construct(integer $status, string $message=NULL, integer $code=0)$statusintegerHTTP状态码,如403,404,500等等。$messagestring错误信息$codeinteger错误代码源码: framework/base/CHttpException.php publicfunction__construct($status,$message=null,$code=0){$this->statusCode=$status;parent::__construct($messa
阅读全文
摘要:1,main.php 里面导入'import' => array( 'application.components.*' ),2,application/components/BaseComponent.php_url = $value; } public function getUrl() { return $this->_url ; } public function test() { return 'test'; }}4,application/components/Controller.phpclass Controller
阅读全文
摘要:让ar执行queryall和queryrow方法返回数组dbActiveGroup(); if(isset(self::$_dbConnections[$activeGroup])) { return self::$_dbConnections[$activeGroup]; } else { $dbConnection = ConnectionHelper::get($activeGroup); if( ! empty($dbConnection) && $dbConnection instanceof CDbConnection) { self::$_dbCo...
阅读全文
摘要:post有3种。1、post方式privatefunction send_post($url,$post_data){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, ...
阅读全文
摘要:main.php://替换所有模板//加载文件名为first的模板// 'theme'=>'theme1', 'components'=>array( //改变主题basepath 'themeManager'=>array( 'basePath' => __DIR__. '/../themes' ),//单个控制器: public function actionIndex(){ Yii::app()->setTheme('theme1');
阅读全文
摘要:<?phpset_time_limit (0);/** $url 图片地址* $filepath 图片保存地址* return 返回下载的图片路径和名称*/function getimg($url, $filepath,$i) { if ($url == '') { return false; } $ext = strrchr($url, '.'); if ($ext != '.gif' && $ext != '.jpg') { return false; } //判断路经是否存在 !is_dir($file
阅读全文
摘要:*/$formname = 'file';$path = 'test';$allowtype_array = array('mp3','txt','jpg');var_dump($_FILES['file']);exit;upload_file($formname,$path,$allowtype_array); /************文件上传函数******************/ /* *$formname Html上传表单名称 *$allowtype_array 允许上传的文件类型数组
阅读全文
摘要:time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒,很奇怪吧 不过这样方便计算, 要找出前一天的时间就是time()-60*60*24; 要找出前一年的时间就是time()*60*60*24*365 那么如何把这个数字换成日期格式呢,就要用到date函数了 $t=time(); echodate("Y-m-dH:i:s",$t); 第一个参数的格式分别表示: a-"am"或是"pm" A-"AM"或是"PM" d-几日,二位数字,若不足二位则前面补零;如:
阅读全文
摘要:Yii里获取当前controller和action的id 在控制器里$name = $this->getId(); // controller$name = $action->id; // action在视图里$name = $this->id = Yii::app()->controller->id; // controller$name = $this->action->id = $this->getAction()->getId(); // action
阅读全文
摘要:为了区分数据是否已转义,我还是建议定义一个命名机制。对于输出到客户机的转义数据,我使用$html数组进行存储,该数据首先初始化成一个空数组,对所有已过滤和已转义数据进行保存。1Welcome back, {$html['username']}.";67?>htmlspecialchars( )函数与htmlentities( )函数基本相同,它们的参数定义完全相同,只不过是htmlentities( )的转义更为彻底。通过$html['username']把username输出到客户端,你就可以确保其中的特殊字符不会被浏览器所错误解释。如果 us
阅读全文
摘要:如果你能正确可靠地识别和过滤输入,你的工作就基本完成了。最后一步是使用一个命名约定或其它可以帮助你正确和可靠地区分已过滤和被污染数据的方 法。我推荐一个比较简单的命名约定,因为它可以同时用在面向过程和面向对象的编程中。我用的命名约定是把所有经过滤的数据放入一个叫$clean的数据 中。你需要用两个重要的步骤来防止被污染数据的注入:经常初始化$clean为一个空数组。加入检查及阻止来自外部数据源的变量命名为clean.实际上,只有初始化是至关紧要的,但是养成这样一个习惯也是很好的:把所有命名为clean的变量认为是你的已过滤数据数组。这一步骤合理地保证了$clean中只包括你有意保存进去的数据,
阅读全文

浙公网安备 33010602011771号