PHP file operations
// Filetype ()
Obtain the object type
// Obtain the file type in windows
Echo filetype ("D :\\ lamp \ php5 \ php. ini ")."";
// The output file indicates a normal file.
Php checks whether the browser is a mobile device
This code can be used to check whether users are using mobile devices to browse the web page.
$ Mobile_browser = '0 ';
If (preg_match ('/(up. browser |
Object-oriented mysql database operations php class
Class database {
Var $ host = NULL;
Var $ username = NULL;
Var $ password = NULL;
Var $ databaseName = NULL;
Var $ link = NULL;
Var $
Php uses GD to create a thumbnail that maintains the aspect ratio
/**
* Create a thumbnail image from $ inputFileName no taller or wider
* $ MaxSize. Returns the new image resource or false on error.
* Author:
PhpXSS security filtering code
Function remove_xss ($ val ){
// Remove all non-printable characters. CR (0a) and LF (0b) and TAB (9) are allowed
// This prevents some character re-spacing such
// Note that
Php returns relative time, such as: 20 minutes ago, 3 days ago
Function plural ($ num ){
If ($ num! = 1)
Return "s ";
}
Function getRelativeTime ($ date ){
$ Diff = time ()-strtotime ($ date );
Comparing the similarity codes of two strings in php
How to Calculate string similarity similar_text and similarity in php
$ First = "abcdefg ";
$ Second = "aeg ";
Echo similar_text ($ first, $ second); result
Use PHP to scale up or down images
Function resizeimage ($ srcfile, $ mySize ){
$ Size = getimagesize ($ srcfile );
Switch ($ size [2]) {
Case 1:
$ Img = imagecreatefromgif ($
Php compresses the file into a zip file
PHP ZipArchive is an extension class that comes with PHP. it can easily compress and decompress ZIP files. before using it, make sure that the php zip extension is enabled.
/*
Convert a php image to an ASCII code
Convert a php image to an ASCII code. after conversion, you can directly display the image using a string.
Ascii
$ Image = 'image.jpg ';
//
PHP calculates the information of a specified folder (number of folders, number of files, and folder size)
// The code can also be used to count the number of directories
// Format the size of the output
PHP calculates the distance between two points on the map
Class GeoHelper
{
/**
* @ Param int $ lat1
* @ Param int $ lon1
* @ Param int $ lat2
* @ Param int $ lon2
* @ Param string
Php dynamically creates a function at runtime
General language functions must be defined as running, while php supports dynamic function creation at runtime. The following is a simple example: create a function based on different
Php + mysql paging
Encapsulated class:
/*************************************** ******
Class name: PageSupport
Function: displays data in the mysql database by page.
**************************************** *
Symmetric encryption algorithm provided by php
KEY is a previously defined constant.Mcrypt: encrypt ();Mcrypt: decrypt ();
Defined ('root') or exit ('Access Denied ');
Class Mcrypt {
Public static
Php obtains the current domain name, host, URL, port, parameter, URL, path, proxy, and so on.
// Obtain the domain name or host address
Echo $ _ SERVER ['http _ host']."";
// Obtain the webpage address
Echo
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service