PHP函数学习之PHP函数点评
函数
PHP函数使用说明,应用举例,精简点评,希望对您学习php有所帮助。
1.print_r()
打印关于变量的易于理解的信息,若为数组,则显示数组的结构信息.
例如:
<br><?php <br/> $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));<br> print_r ($a);<br>?><br>
axgle点评:查看任何数组的结构信息,是程序调试的必备工具。对于任何返回结果是数组的“函数”,只要print_r一下,一切底细一目了然!
2.var_export()
输出或返回一个变量的字符串表示
此函数返回关于传递给该函数的变量的结构信息,它和print_r() 类似,不同的是其返回的表示是合法的 PHP 代码。
您可以通过将函数的第二个参数设置为 TRUE,从而返回变量的表示。
例如:
<br><?php <br/>$a = array (1, 2, array ("a", "b", "c"));<br>var_export ($a);<br><br>echo "<hr>";<br><br>$v = var_export($a, TRUE);<br>echo $v;<br><br>?><br>
axgle点评:上面例子中,$v = var_export($a, TRUE)返回的是php代码噢~~那么您就可以把它保存为php文件。
保存为php文件做什么?呵呵,这可以用作“缓存”,当需要的时候,可以直接include它。
3.file()
file() 将文件作为一个数组返回。数组中的每个元素都是文件中相应的一行,包括换行符在内。如果失败 file() 返回 FALSE。
<br><?php <br/>// 将一个文件读入数组。<br>$lines = file('test.txt');<br><br>//查看这个数组的结构<br>print_r($lines); <br><br>?> <br>
axgle点评:file()函数是我接触php的初期让我非常惊讶的的一个函数。相比以前我在c语言和vb里对
文件读写的无比麻烦的经历,使得当时的我感觉再也没有比file()函数更方便的文件读写方式了。
4.phpinfo()
打印与php有关的信息,例如PHP版本,功能支持,全局变量等.
例如:
phpinfo();
?>
axgle点评:简单的一个函数,让你时刻了解php的飞速发展---若您密切关注php的发展的话~~~~
5.file_get_contents() (注:PHP 4 >= 4.3.0, PHP 5)
将整个文件读入一个字符串.file_get_contents() 函数是用来将文件的内容读入到一个字符串中的首选方法。如果操作系统支持还会使用内存映射技术来增强性能。
例如:
$data = file_get_contents('test.txt');
echo $data;
?>
6. file_put_contents (注:PHP 5)
将一个字符串直接写入文件.
[1] [2] 下一页

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
