
php
代码修行者
这个作者很懒,什么都没留下…
展开
-
mysql 表名 纯数字
一般不建议用纯数字命名表名使用纯数字表名 要在表名前后加上 ``感叹号左边的那个键sql举例 insert into `112` values(1,2,3,4,5);原创 2013-12-27 10:34:38 · 9400 阅读 · 0 评论 -
php 学习记录 ajax responseXML Text
在XHR(XMLHttpRequest)1.0标准中response 只有 xml 和 text , json 也是 text一:XML XHR = new XMLHttpRequest(); XHR.open('POST','1.php',true); XHR.setRequestHeader("Content-type","application/x-www-form-ur原创 2013-08-28 21:45:12 · 952 阅读 · 0 评论 -
无刷新 投票 方法 不用ajax
方法一:在 php 端header('HTTP/1.1 204 No Content ');利用http的原理进行方法二:利用src图片加载的特性完成请求写一个函数,函数体内 var img = document.createElement('img');img.setAttribute('src','***.jpg');然后绑定要点击的元素转载 2013-08-27 13:49:37 · 1040 阅读 · 0 评论 -
php apache 缓存操作
利用协议控制缓存相关模块: mod_expiresExpiresActive OnExpiresByType image/jpeg "access plus 1 month"利用协议取消缓存客户端:Cache-Control:no-cachePragma:no-cache服务器端 清除Cac转载 2013-08-26 23:43:12 · 1365 阅读 · 0 评论 -
php apache 压缩
开启deflate模块在 httpd.conf 写入如下 代码DeflateCompressionLevel 6AddOutputFilterByType DEFLATE text/plainAddOutputFilterByType DEFLATE text/htmlAddOutputFilterByType DEFLATE text/xmlAddOutput转载 2013-08-26 23:28:53 · 601 阅读 · 0 评论 -
php referer 防盗链
初级的php程序员一定会想到,包括我在写这篇文章前 if($_SERVER['HTTP_REFERER'] ...) //然后正则匹配也好,判断也好 { header('XXX'); }可是这样只不过是自欺欺人,防盗链的目的,并不是不让其他网页看自己家的东西,而是缓解自家网站的压力这样的写法,根本无法达到缓解服务器压力的目的防盗链应该要从服务器入原创 2013-08-26 17:47:04 · 1106 阅读 · 0 评论 -
php xml xpath 很好用
$dom = new DOMdocument('1.0','utf-8'); $dom->load('./dictionary.xml'); $xpath= new DOMXPATH($dom); header('Content-type:text/html;charset=utf-8'); $query = '/haou_dict/DicEn[Name="programmer"]/Co原创 2013-08-24 17:25:48 · 1242 阅读 · 0 评论 -
php 网站重定向 数据提交
header('www.baidu.com',true,307);301 永久重定向302 临时重定向304 未修改,与客户端缓存有关307重定向中保持原有的请求数据原创 2013-08-24 21:55:43 · 1037 阅读 · 0 评论 -
simplexml to array and array to xml
function sxml2arr($xml) { $arr = (array)$xml; foreach ($arr as $key => $value) { if($value instanceof simplexmlElement || is_array($value)) { $arr[$key] = sxml2arr($value); } } r原创 2013-08-24 15:18:54 · 1064 阅读 · 0 评论 -
php xml 动态生成 rss 源
<?php class addrss { public $title; public $link; public $description; protected $dom; protected $templates = './rsstemplate.xml'; function __construct() { $this->dom = new DOMdocu原创 2013-08-24 13:13:05 · 1043 阅读 · 0 评论 -
php 小功能 (垃圾代码) 把中文 数字 替换成 阿拉伯数字
<?php $path = iconv('utf-8','gbk','D:/baiduyundownload/lampPHP/特'); //转换编码,因为是中文目录,反正无法识别 $dir = opendir($path); while($filename=readdir($dir)) { if(stripos($filename,'wmv')) //只有wmv文件 才替换原创 2013-08-23 16:14:37 · 1589 阅读 · 0 评论 -
php smarty 缓存总结
自己定义一个类继承smarty类方便操作 require '../Smarty/libs/Smarty.class.php'; class mySmarty extends Smarty { function __construct() { parent::__construct(); $this->setTemplateDir('./temp');原创 2013-08-17 19:05:40 · 676 阅读 · 0 评论 -
php学习记录 ajax 状态码
0:XHR对象刚创建的时候1:open成功后为1,此时已经连接成功2:接受头信息完毕后3:接受body信息完毕后 有可能3出现多次,原因是 body信息大小不明,分开传输4:成功转载 2013-08-30 15:52:20 · 735 阅读 · 0 评论 -
php学习记录 jsonp
function search() { var keywords = document.getElementsByName('keywords')[0].value; var url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q='+keywords+'&callback=aa'; var sc原创 2013-08-30 15:32:42 · 753 阅读 · 0 评论 -
php pdo 执行 like查询
$sql1 = 'SELECT count(*) FROM u_goods WHERE title LIKE :title';$query->bindValue(':title','%'.$search_kw.'%');上面这样做才是正确的下面这样是没有数据的$sql1 = 'SELECT count(*) FROM u_goods WHERE title LIKE原创 2013-12-18 10:56:02 · 4454 阅读 · 0 评论 -
apache 高并发 配置
httpd.conf原创 2013-12-01 14:11:03 · 1489 阅读 · 0 评论 -
php 局部动态
html: php:<?php echo "document.write('123')\r\n";// \r\n 换行 为了避免 如果html中的下一行代码会挤上来 可能造成乱码原创 2013-11-28 16:56:39 · 726 阅读 · 0 评论 -
php 编程 小技巧
<?php //将数据分类成2为数组$str='电影|忠犬八公的故事游戏|侠盗猎车动漫|火影忍者游戏|超级玛丽游戏|植物大战僵尸电影|放牛班的春天';$arr = array();foreach(explode(PHP_EOL,$str) as $v){ $data = explode('|',$v); $arr[$data[0]][]=$data[1];}header原创 2013-11-28 16:21:19 · 808 阅读 · 0 评论 -
把 对象存到 文件中
//保存file_put_content('文件名',serialize(对象));//恢复unserialize(file_get_content('文件名'));原创 2013-11-27 21:27:47 · 813 阅读 · 0 评论 -
php empty 注意
$i = 0;empty($i); //true$i="0";empty($i);//true//但是$i = "-0"empty($i); //false原创 2013-10-17 22:36:42 · 804 阅读 · 0 评论 -
smarty truncate
Example 5-21. truncate例5-21.截取index.php:$smarty = new Smarty;$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');$smarty->display('index.tp转载 2013-08-20 15:48:17 · 826 阅读 · 1 评论 -
php学习记录 html5 createObjectURL
直接将文件的二进制转成图片,发货url地址,显示在页面上 function up() { var file = document.getElementsByName('pic')[0].files[0]; var img = document.createElement('img'); img.src = window.URL.createObjectURL(file原创 2013-08-31 23:30:40 · 1753 阅读 · 0 评论 -
php学习记录 iframe 文件上传
function upload() { document.getElementsByName('process')[0].innerHTML=""; }原创 2013-08-31 00:53:15 · 716 阅读 · 0 评论 -
php 学习记录 formdata 文件上传 ajax html5
formdata function send() { var form = document.getElementById('form'); fdata = new FormData(form); XHR = new XMLHttpRequest(); XHR.open('POST','formdata.php',true); XHR.onready原创 2013-08-31 23:28:54 · 3021 阅读 · 0 评论 -
php Dom 解析
原创 2013-08-23 14:52:33 · 846 阅读 · 0 评论 -
php xml 规范
1:XMl 重要性: 非常重要, 因为计算机世界的通用语言., 是我们学习Ajax,Webservice的基础是服务器之间交换数据常用的语言.2:XML出现的历史背景要替换掉html3:为什么要替换掉html?答: 因为html中的信息,既有显示效果,如h1,h2显示效果不同,又有数据信息,给数据的交换,解析,带来极大不变4:转载 2013-08-23 13:21:40 · 673 阅读 · 0 评论 -
php学习之smarty 三种 值 获取方式
1.assign分配 $smarty->assign("title","测试标题"); $smarty->assign("content","测试内容");2保留变量{$smarty.get.id}{$smarty.const.NIHAO}3读取配置文件{config_load file='tong.conf'}{#name#}//读取方式或者{smarty.原创 2013-08-09 15:25:39 · 1294 阅读 · 0 评论 -
php smarty模板原理 示例
<?php class mini { protected $templates_dir = ''; //模板路径 protected $compile_dir = ''; //编译存放目录 protected $temp_var_arr = array();//外部变量分配到此数组 public function __construct($templates_dir,$comp原创 2013-08-08 13:46:57 · 840 阅读 · 0 评论 -
php 函数小记quotemeta
quotemeta<?php $str = "Hello world. (can you hear me?)"; echo quotemeta($str); ?>在字符串中某些预定义的字符前添加反斜杠原创 2013-08-08 12:34:09 · 882 阅读 · 0 评论 -
smarty 模板包含
Example 7-6. function includeSmarty手册范例 7-6. include 函数演示{include file="header.tpl"}{* body of template goes here *}{include file="footer.tpl"}You can also pass转载 2013-08-20 15:46:21 · 836 阅读 · 0 评论 -
在项目中使用 smarty 之 自动加载
首先,请看一段代码<?php function autoaaa($class) { echo '111'.$class; include './'.$class.'.php'; } function autobbb($class) { echo '222'.$class; } spl_autoload_register('autoaaa'); spl_autol原创 2013-08-20 15:09:26 · 1285 阅读 · 0 评论 -
php smarty 删除缓存
$smarty->clearCache('1.html');注意: clearCache操作会删除与之相对应的索引缓存,比如 1.html?id=1 1.html?id=2 .....在开发阶段不希望使用缓存$smarty->force_cache=true;原创 2013-08-20 14:24:44 · 723 阅读 · 0 评论 -
分页类 主要函数
public function show() { if($this->page/$this->pageSize > $this->pageCount) { $this->page =1; } $nav = array(); $nav[0] = "".$this->page.""; for($left = $this->page-1,$right =$原创 2013-08-06 15:04:20 · 784 阅读 · 0 评论 -
php 单例模式 基于SESSION
在编写商城购物车的时候需要用到<?php session_start(); class cartTool { static protected $ins=NULL; public $hash; function __construct() { $this->hash = mt_rand(1111,333333); } static public functi原创 2013-08-04 12:30:26 · 1087 阅读 · 0 评论 -
php 单例模式 笔记
class cartTool { static protected $ins = null; public $hash = null; function __construct() { $this->hash = mt_rand(11111,333333); } static public function getInstance() { if(self:原创 2013-08-04 12:12:31 · 714 阅读 · 0 评论 -
php学习笔记1--根据条件调用不同的函数
在使用GD2库的时候,imagefromjpg,imagefrompng.....等根据图片类型来使用的函数怎么才能根据图片类型自动调用对应函数呢方法一:switch语句 switch ($temp['ext']) { case 'png': return imagecreatefrompng($fileName); case原创 2013-07-26 14:36:34 · 1048 阅读 · 0 评论 -
php smarty高级 对象注册
$human = new human('小花'); $smarty->assign('human',$human); $smarty->display('1.tpl');tpl:{$title} {$human->say()}结果大家好,我叫小花 这样用 assign分配对象的方法不好,因为有些不希望前端人员调用的方法,可能被无意原创 2013-08-22 17:49:41 · 782 阅读 · 0 评论 -
php Smarty 高级 模板继承
1.tpl{block name = 'title'}{/block}{block name = 'content'}{/block}{block name = 'footer'}{/block}2.tpl{extends file='1.tpl'}{block name='title'}我就是标题{/block}{block name='content'}我就是原创 2013-08-22 18:22:39 · 899 阅读 · 0 评论 -
php 高级 自定义 变量调节器(不错的玩意)
首先 在 ./Smarty/libs/plugins 下面新建 文件 modifier.repeat.php 红色字体为 自定义的调节器 的 名称 function smarty_modifier_repeat($string,$count) { $temp=''; for ($i=0; $i <$count ; $i++) { $temp.=$string;原创 2013-08-22 18:49:54 · 851 阅读 · 0 评论 -
php xml 删除节点 替换节点 修改节点
<?php//删除节点 $dom = new DOMDocument('1.0','utf-8'); $dom -> load('1.xml'); $zf = $dom->getElementsByTagName('character')->item(0); $zf->parentNode->removeChild($zf);//替换节点 (不能修改,以替换达到修改的结果) $h原创 2013-08-23 23:23:03 · 2448 阅读 · 0 评论