search
Homephp教程php手册PHP中常用函数的使用说明

1.重复一个字符串或者符号多少次

str_repeat("=", 3

结果 ‘===’

2.随机抽出1个或者多个key

 $a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");

 array_rand($res,1);

结果 ‘c’

3.返回二维数组的一列,重新组成一个一维数组

 $a=array( ['a'=>1,'b'=>2],   ['a'=>3,'b'=>4], ['a'=>5,'b'=>6]);

array_column($a, 'b')

结果 一维数组[2,4,6]

3.获取files文件 图片长宽

  $img_info = getimagesize($_FILES['urlPic']['tmp_name']);

  $img_bili = $img_info[0]/$img_info[1];  //判断图片比例 图片宽除以高

4.把整个文件读入一个数组中

 file($_FILES['url']['tmp_name']);

5.截取、查找字符串

截取字符串中最后一个标记后的字符串 如 1.0.1.300

strrchr("1.0.1.300", ".")  从某个字符串从最后出现的位置截取到结尾 结果 0.300

substr(strrchr("1.0.1.300", "."), 1)  //从指定位置开始截取字符串,可以指定截取的长度 结果 300

strstr("1.0.1.300", ".") = strchr(,) //从前面第一次出现某个字符串的地方截取到最后 结果 .0.1.300

strpos("1.0.1.300", ".") //某个字符串第一次出现的位置 下标从0开始  结果 1

strrpos("1.0.1.300", ".") //某个字符串最后一次出现的位置 下标从0开始  结果 5

6.保留小数点后几位有效数的函数 千位分组来格式化数字

number_format("10000",2) 结果1,0000.00  

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 Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

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),