<?php教程/* 1.jpg为你想获得其尺寸的图片 */
$arr = getimagesize("1.jpg");
/**
* 这里$arr为一个数组类型
* $arr[0] 为图像的宽度
* $arr[1] 为图像的高度
* $arr[2] 为图像的格式,包括jpg、gif和png等
* $arr[3] 为图像的宽度和高度,内容为 width="xxx" height="yyy"
*/
/* 以下两行代码输出的内容都是一样的 */
echo "<img src="1.jpg" $arr[3] alt="" />";
echo "<img src="1.jpg" width="$arr[0]" height="$arr[1]" alt="" />";
?>
php连接mysql数据库类
//调用 方法
?>
又一款php分页类代码
class multipage {
var $total;
var $perpage;
var $pages;
var $maxpage;
var $offset = 9;
var $curr_page;
function init($total, $perpage, $maxpage) { //初始化页数
$this->total;
$this->perpage;
$this->maxpage;
$this->offset = 9;
}
function getpagelist() {//获取分页列表
$result_pages = "";
$this->pages = ceil($this->total / $this->perpage);
if ($this->pages > $this->maxpage) {
$from = $this->curr_page - $this->offset;
if ($from < 1) {
$from = 1;
}
$to = $from + $this->maxpage - 1;
if ($to > $this->pages) {
$to = $this->pages;
if (($to - $from) < $this->maxpage) {
$from = $from - 1;
}
}
} else {
$from = 1;
$to = $this->pages;
}
$p = 0;
for($i = $from; $i <= $to; $i++) {
$result_pages[$p] = $i;
$p++;
}
return $result_pages;
}
function getfirst() { //获取第一页
if ($this->curr_page > 1 && $this->pages > 1) {
return 1;
} else {
return "";
}
}
function getlast() { //取末页
if ($this->pages > 1 && $this->curr_page < $this->pages) {
return $this->pages;
} else {
return "";
}
}
function getprev() {//上一页
$prevpage = $this->curr_page - 1;
if ($prevpage > 0) {
return $prevpage;
} else {
$prevpage = "";
return $prevpage;
}
}
function getnext() {//下一页
$nextpage = $this->curr_page + 1;
if ($nextpage <= $this->pages) {
return $nextpage;
} else {
$nextpage = "";
return $nextpage;
}
}
function gettotal() {//共多少页
if ($this->pages > 0) {
return $this->pages;
} else {
return 1;
}
}
}
php登录代码
session_start();
/* get post */
if (!function_exists("getpost")){function getpost(){if(count($_post)){foreach($_post as $key => $value){global ${$key};${$key}=$value;}}}}
php判断大小写字母函数
方法二
php取得当前时间函数
方法一date函数
//2010-08-29 11:25:26
php中的日期时间函数(1/6)
得到目前的日期和时间-我们有多少种方式?
2、 改变日期显示的方式-日期和时间的显示形式
3、 转换现在的日期为unix的时间戳值
4、 改变日期
a. 增加时间
b. 减去时间
c. 找出两日期之间的间隔
5、 为php教程添加dateadd函数
6、 为php添加datediff函数
php中rename()函数
php filesystem 函数
rename() 函数重命名文件或目录。
若成功,则该函数返回 true。若失败,则返回 false。
rename(oldname,newname,context)
参数
描述
oldname
必需。规定要重命名的文件或目录。
newname
必需。规定文件或目录的新名称。
context
必需。规定文件句柄的环境。context 是可修改流的行为的一套选项。
注释:在 php 4.3.3 之前,rename() 不能在基于 *nix 的系统中跨磁盘分区重命名文件。
注释:用于 oldname 中的封装协议必须和用于 newname 中的相匹配。
注释:对 context 的支持是 php 5.0.0 添加的。
<?php
rename("images","pictures");
?>
oldpath ----文件或目录原来路径
$newpath ----新定义路径
那么 rename($oldpath,$newpath)就可以完成文件/目录移动的操作
经过我的测试,win32和unix的php4版本都支持这个功能。
另外,好象php4的win32版取消了unlink()函数。那么还可以巧用rename()函数来完成删除的操作,例如:
$path ---- 文件或目录路径
$tmp ---- tmp目录(/tmp)
用rename($path,$tmp) 将文件移动到tmp目录.
PHP isset()函数与empty()函数区别
empty 判断一个变量是否为“空”,isset 判断一个变量是否已经设置。正是这种所谓的“顾名思义”,令我开始时走了些弯路:当一个变量值等于0时,empty()也会成立(true),因而会发生一些意外。原来,empty 和 isset 虽然都是变量处理函数,它们都用来判断变量是否已经配置,它们却是有一定的区别:empty还会检测变量是否为空、为零。当一个变量值为0,empty 认为这个变量同等于空,即相当于没有设置。
比如检测 $id 变量,当 $id=0 时,用empty 和 isset 来检测变量 $id 是否已经配置,两都将返回不同的值—— empty 认为没有配置,isset 能够取得 $id 的值:
php ajax仿dedecms 验证新闻是否存在
<script language="网页特效">
function startrequestusingpost() {
if(checktitle()==false)
{
return;
}
var title = document.getelementbyid("title").value;
createxmlhttprequest();
xmlhttp.open("post","checkntype",true);
xmlhttp.onreadystatechange = processresponse;
xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded");
xmlhttp.send("title=" + title);
}
function processresponse() {
if(xmlhttp.readystate == 4) {
if(xmlhttp.status == 200) {
var result = xmlhttp.responsetext;
if(result==1){
document.getelementbyid("message").style.display="inline";
document.getelementbyid("btnadd").disabled="disabled";
}else
{
document.getelementbyid("message").style.display="none";
document.getelementbyid("btnadd").disabled="";
}
}
}
}
function checktitle()
{
var title=document.getelementbyid("title").value;
if(title=="")
{
document.getelementbyid("lbltitle").style.display="inline";
return false;
}else
{
document.getelementbyid("lbltitle").style.display="none";
return true;
}
}
PHP删除数组重复元素函数
function delsame(&$array)
{
$i = 0;
while(isset($array[$i]))
{
$j = $i + 1;
while(isset($array[$j]))
{
if($array[$i] == $array[$j]) //如果发现后面有重复的元素
{
delmember($array, $j); //把它删除
$j--; //重新检查补上来的元素是否是重复的
}
$j ++;
}
$i ++;
}
}
php 遍历二维数组与多维数组代码
//php遍历多维数组
//实例三,遍历二维数组