php 批量删除文件
elseif($doing == 'delfiles') {
if ($dl) {
$dfiles='';
$succ = $fail = 0;
foreach ($dl as $filepath => $value) {
if (@unlink($filepath)) {
$succ++;
} else {
$fail++;
}
}
m('删除文件 '.count($dl).' 成功 '.$succ.' 失败 '.$fail);
} else {
m('请选择文件');
}
php 复制目录及目录下所有文件
function copy($from, $to) {
if ($this->abspath($to)=="/") $to=$this->basedir;
if ($this->dirname($from) == $this->dirname($to)) $to = $this->dirname($to).'/复件'.basename($from);
if (!is_dir($from)) {
return @copy($from, $to);
} else {
if (!is_dir($to)) @mkdir($to);
$path = opendir($from);
while( $file = readdir( $path ) ) {
if (($file=='.')||($file=='..')) continue;
if (is_dir($from.'/'.$file)) $this->copy($from.'/'.$file, $to.'/'.$file);
else echo basename($file), copy($from.'/'.$file, $to.'/'.$file) ? ' Success!' : ' False.', '<br />';
}
return true;
}
}
php 获取系统当前路径与检查php配置参数
php 获取系统当前路径与检查php配置参数
function getPath($mainpath, $relativepath) {
global $dir;
$mainpath_info = explode('/', $mainpath);
$relativepath_info = explode('/', $relativepath);
$relativepath_info_count = count($relativepath_info);
for ($i=0; $i<$relativepath_info_count; $i++) {
if ($relativepath_info[$i] == '.' || $relativepath_info[$i] == '') continue;
if ($relativepath_info[$i] == '..') {
$mainpath_info_count = count($mainpath_info);
unset($mainpath_info[$mainpath_info_count-1]);
continue;
}
$mainpath_info[count($mainpath_info)] = $relativepath_info[$i];
} //end for
return implode('/', $mainpath_info);
}
php 类的静态变量的初始化
共有的成员还有办法解决,例如:
class A {
static public $child;
}
A::$child = new B();
对于私有的成员似乎就没有什么干净的方法了,只能这样做:
class A {
static private $child;
static public initialize() {
self::$child = new B();
}
}
A::initialize();
php POST GET 数据过滤函数
foreach(array('_GET','_POST') as $_request) {
foreach($$_request as $_key => $_value) {
if ($_key{0} != '_') {
if (IS_GPC) {
$_value = s_array($_value);
}
$$_key = $_value;
}
}
}
php 批量保存数据与批量更新数据
if ($insert && $insertsql) {php 批量保存数据与批量更新数据
$keystr = $valstr = $tmp = '';
foreach($insertsql as $key => $val) {
if ($val) {
$keystr .= $tmp.$key;
$valstr .= $tmp."'".addslashes($val)."'";
$tmp = ',';
}
}
if ($keystr && $valstr) {
dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
m(q("INSERT INTO $tablename ($keystr) VALUES ($valstr)") ? 'Insert new record of success' : mysql_error());
}
}
if ($update && $insertsql && $base64) {
$valstr = $tmp = '';
foreach($insertsql as $key => $val) {
$valstr .= $tmp.$key."='".addslashes($val)."'";
$tmp = ',';
}
if ($valstr) {
$where = base64_decode($base64);
dbconn($dbhost,$dbuser,$dbpass,$dbname,$charset,$dbport);
m(q("UPDATE $tablename SET $valstr WHERE $where LIMIT 1") ? 'Record updating' : mysql_error());
}
}
php 显示今天是星期几与一年的每几天代码
php 显示今天是星期几与一年的每几天代码
public function getPart ($part) {
$source = $this->timestamp;
switch($part)
{
case 'yy' : $result = intval(date("Y", $source)); break; //年
case 'mm' : $result = intval(date("m", $source)); break; //月
case 'dd' : $result = intval(date("d", $source)); break; //日
case 'w' : $result = intval(date("N", $source)); break; //星期 [1-7] "1"表示星期一
case 'cw' : $index = date("N", $source); //中文星期
$week_array = array('1'=>'一', '2'=>'二', '3'=>'三', '4'=>'四', '5'=>'五', '6'=>'六', '7'=>'日');
$result = '星期' . $week_array[$index];
php 正则html网址代码
php 正则html网址代码
$pattern = "/[w-]+.(com|net|org|gov|cc|biz|info|cn)(.(cn|hk))*/";
preg_match($pattern, http://pic4.phprm.com/2015/07/04/$url.jpg, $matches);
if(count($matches) > 0) {
return $matches[0];
}else{
$rs = parse_url($url);
$main_url = $rs["host"];
if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)) {
return $main_url;
}else{
$arr = explode(".",$main_url);
$count=count($arr);
$endArr = array("com","net","org","3322");//com.cn net.cn 等情况
if (in_array($arr[$count-2],$endArr)){
$domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];
}else{
$domain = $arr[$count-2].".".$arr[$count-1];
}
return $domain;
}// end if(!strcmp...)
}// end if(count...)
}// end function
php image_type_to_mime_type
php image_type_to_mime_type
image_type_to_mime_type - 获取MIME的图像类型和getimagesize返回类型,exif_read_data,exif_thumbnail,本函数
取本周第一天的日期 每周第一天是星期几
取本周第一天的日期 每周第一天是星期几
* 设置每周第一天是星期几
* @param string $week 星期0-6
* @return void
*/
public function setFirstDayOfWeek($week = 1) {
$this->firstDayOfWeek = $week;
}
ajax+php检测文章标题是否存在代码
ajax+php检测文章标题是否存在代码
php代码
function checkTitle()
{
$title = PostGet('title');
if( empty( $title ) )
{
return false;
}
else
{
$Db = new Db();
$row = $Db->query("Select * from news where title ='$title'");
if( $Db->rows( $row ) )
{
echo 1;
}
else
{
return NULL;
}
}
}
js代码
function createXMLHttpRequest(){//创建XMLHttpRequest对象
if(window.ActiveXObject){//IE
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
return;
}
}else if(window.XMLHttpRequest){//Mozilla,firefox
try {
return new XMLHttpRequest();
} catch(e){
return;
}
}
}
php elseif 与else if区别
php elseif 与else if区别
if、elseif 以及 else 语句用于执行基于不同条件的不同动作。