Home> php教程> php手册> body text

PHP常用函数小技巧

WBOY
Release: 2016-06-13 12:27:11
Original
762 people have browsed it

1. 返回文件扩展名
function getformat($file)
{
$ext=strrchr($file,".");
$format=strtolower($ext);
return $format;
}

2.格式化变量

$num = 1;
printf("%04d", $num);
?>

3.php重定向网页
// 例如重定向到www.cgsir.com (注意重定向之前不要有html内容)
header("location:http://www.jb51.net");

echo " ";

4.限制上传的文件大小
//$limit_size为限制最大文件大小
$limit_size=50000;
$file_size=$HTTP_POST_FILES['ufile']['size'];
if($file_size >= $limit_size) {
echo "你的文件超过的限制的大小
";
echo "你的文件大小为= ".$file_size;
echo " K";
echo "
文件大小限制为= 50000 k";
}
else {
// 上传到什么目录,也就是从临时目录拷贝到目标目录
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "上传成功
";
echo "PHP常用函数小技巧";
}

5.php常用的对字符串进行加密的算法:
5.1 $db_password = md5($random_password);
5.2 $db_password = sh1($random_password);

6.退出登录
// 退出登录
session_start();
include_once('includes/header.php');
if (isset($_SESSION['user_id']))
{
unset($_SESSION['user_id']);
session_destroy();

echo '

';
echo ' 成功退出!
';
echo '

正在跳转,请稍等......

';
echo '';
echo ' 直接返回

';
echo '
';
exit(0);
}
else
{
echo ' 您还没有登录呢!';
}

include_once('includes/footer.php');
?>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!