search
Homephp教程php手册PHP常用函数小技巧

PHP常用函数小技巧

Jun 13, 2016 pm 12:27 PM
extfilefunctionphpfunctionSmallCommonly usedextension nameSkilldocumentreturn

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');
?>
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment