函数
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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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

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.
