![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
php
末世剩人
工工作队
展开
-
遍历目录
function traverse_scandir($dir) { $files = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($han原创 2011-09-21 11:40:39 · 80 阅读 · 0 评论 -
Linux 安装PHP配置参数
在Linux下安装PHP,源代码方式安装,总需要配置很多参数。这里列出常用配置参数,并详细用中文解释说明了。给大家一些参考./configure--prefix=/usr/local/PHP php 安装目录--with-apxs2=/usr/local/apache/bin/apxs--with-con转载 2012-06-22 16:14:47 · 2005 阅读 · 0 评论 -
利用php在图片上写字(中英文)
<?php/*param $image 图象资源param size 字体大小param angle 字体输出角度param showX 输出位置x坐标param showY 输出位置y坐标param font 字体文件位置param content 要在图片里显示的内容*/class showChinaText { var $text =转载 2012-10-23 15:28:38 · 9577 阅读 · 1 评论 -
linux php扩展模块安装。
需要安装扩展shmop找到php安装源文件目录# cd /usr/local/php-5.4.0/ext/shmop# /usr/local/php/bin/phpize# ./configure --with-php-config=/usr/local/php/bin/php-config# make && make install编译安装成功# cd /usr转载 2013-04-08 11:08:01 · 1257 阅读 · 0 评论 -
最简单的xml操作方式!
$file='test.xml';if(!file_exists($file)){ file_put_contents($file,'');}$xml = simplexml_load_file($file);$lottery = $xml->addChild('lottery','http://www.178cpw.com');//增加节点lottery 并给节点加内容$lotte原创 2012-09-12 09:46:11 · 924 阅读 · 0 评论 -
判断url是否存在
/** * 判断url是否存在 */function is_url_exist($url) { $array = get_headers($url, 1); if (preg_match('/200/', $array[0])) { return true; } else { return false; }}原创 2013-05-24 17:31:07 · 933 阅读 · 0 评论 -
PHP获取中文汉字首字母方法
function getFirstLetter($str){ $fchar = ord($str{0}); if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($str{0}); $s1 = iconv("UTF-8","gb2312", $str); $s2 = iconv("gb2312"转载 2013-08-27 15:19:28 · 1924 阅读 · 0 评论 -
sql防注入代码
function defend_sql($string, $force = 1) { $preg = "select|insert|and|or|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile"; if(!get_magic_quotes_gpc() || $force) { if(原创 2013-08-27 14:47:28 · 824 阅读 · 0 评论 -
获取字符串的长度!
今天无意间看ECSHOP的源码,看到获取中文字符串的长度的代码,感觉这个思路很不错。/** * 计算字符串的长度(汉字按照两个字符计算) * * @param string $str 字符串 * * @return int */function str_len($str){ $length = strlen(preg_replace('/[原创 2013-10-21 16:18:19 · 818 阅读 · 0 评论 -
数字转中文
<?phpfunction num2str($num){ $unit=array('','十','百','千'); $units=array('','万','亿','兆'); $n2s=array('零','一','二','三','四','五','六','七','八','九'); $s2=strrev($num);//倒转字符串。 $r=""; $i4=-1; $zero="";转载 2012-02-22 15:27:28 · 93 阅读 · 0 评论 -
PHP冒泡算法
function direct_sort($data) { $count = count($data); if($count == 0) return; elseif($count == 1) return $data; for($i = 0; $i for ($j = $i + 1; $j原创 2011-09-20 17:19:05 · 545 阅读 · 0 评论 -
PHPDocumentor安装与使用(转)
PHPDocumentor安装与使用By kuco |Published:2011/04/07PHPDocumentor 是一个用PHP写的工具, 对于有规范注释的php程序, 它能够快速生成具有相互参照,索引等功能的API文档.安装环境:本机安装的是 EasyPHP-5.3.2i 套件,1安装目录是 D:\Program Files\Eas转载 2011-10-27 17:27:57 · 3179 阅读 · 0 评论 -
function lookandsay!
function lookandsay($s) { $r = ''; $m = $s[0]; $n = 1; for ($i =1, $j = strlen($s); $i < $j; $i ++) { if ($s[$i] == $m) { $n ++; } else { $r .= $n.$m; $m = $s[$i]; $n = 1; } }转载 2011-11-29 15:51:59 · 577 阅读 · 0 评论 -
获取今年所有星期天的日期!
$now = time(); $today = getdate(); $start_day = getdate($now - $today['yday'] * 3600 * 24);//获取今年第一天的时间戳 $first_sunday = $now - ($today['yday'] - (7 - $start_day['wday'])) * 3600 * 24;原创 2011-12-15 10:33:42 · 136 阅读 · 0 评论 -
(随感)为什么要把常量放在==的左边?
以前在看到形如if(10 == $var) {...}时,怎是想为什么要把常量放左边,刚看到《PHP经典实例》才明白,原来是防止错把==写成=,那样条件就一直成立,并且不易发觉,但把常量放在左边就会报错!原创 2011-12-15 15:55:07 · 1959 阅读 · 0 评论 -
格式化输出数组.
function pc_grid_horizontal($array, $size) { $table_width = 100; $width = intval($table_width / $size); $tr = ''; $td = "%s"; $grid = "$tr"; $i = 0; foreach ($array as $e) { $grid .= sp转载 2011-12-15 15:41:54 · 5397 阅读 · 0 评论 -
不使用第三个变量,交换两个变量的值!
不使用第三个变量,交换两个变量的值!以前就看到过这样的笔试题,今天无意间发觉一种超级简单的方法!估计你看到了也会大吃一惊。list($b, $a) = array($a, $b);够神吧!原创 2011-12-15 16:05:16 · 584 阅读 · 0 评论 -
PHP筛选法求质数。
参照了网上的一些写法和想法function sift_prime($max) { for ($i = 2; $i <= $max; $i ++) {//把值赋值为bool,加快存取速度 $data[$i] = true; } for ($i = 2; $i < $max; $i ++) if (true == $data[$i]) for ($j = $i + 1; $原创 2011-12-16 15:25:31 · 1559 阅读 · 0 评论 -
试除法求质数的最快方法!
function prime($max) { $data[0] = 2; $total = 1; for ($i = 3; $i <= $max; $i += 2) { $flag = true; $sqrt = ceil(sqrt($i)); for ($j = 0; $j < $total && $data[$j] <= $sqrt; $j ++) { if (0 ==转载 2011-12-16 11:20:00 · 1776 阅读 · 0 评论 -
dedecms一些技巧
有时我们很多栏目公用一个模版,但栏目展示的图片又不同,并且要考虑到多级栏目下的{dede:field.typeid function="GetTopid(@me)"/}这个能获取到栏目的顶级ID,不同的栏目图片加上不同的ID就可以了。原创 2014-06-03 22:45:26 · 1313 阅读 · 0 评论