Home php教程 php手册 PHP函数学习之PHP函数点评

PHP函数学习之PHP函数点评

Jun 21, 2016 am 09:11 AM
file gt lt nbsp 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>
Copy after login


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>
Copy after login


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>
Copy after login


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] 下一页  



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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles