php 根本函数
php 基本函数
定义常数
define('APPCONFIG','plaConfig');
获取常数
echo constant('APPCONFIG')."\n";
echo APPCONFIG."\n";
常数不能定义两次
初始化变量值
ini_set('display_errors',1);
获取变量值。
echo ini_get('display_errors')."\n";
用PHP的
ob_start();
相关函数简介:
1、Flush:刷新缓冲区的内容,输出。
函数格式:flush()
说明:这个函数经常使用,效率很高。
2、ob_start :打开输出缓冲区
函数格式:void ob_start(void)
说明:当缓冲区激活时,所有来自PHP程序的非文件头信息均不会发送,而是保存在内部缓冲区。为了输出缓冲区的内容,可以使用ob_end_flush()或flush()输出缓冲区的内容。
3 、ob_get_contents :返回内部缓冲区的内容。
使用方法:string ob_get_contents(void)
说明:这个函数会返回当前缓冲区中的内容,如果输出缓冲区没有激活,则返回 FALSE 。
4、ob_get_length:返回内部缓冲区的长度。
使用方法:int ob_get_length(void)
说明:这个函数会返回当前缓冲区中的长度;和ob_get_contents一样,如果输出缓冲区没有激活。则返回 FALSE。
5、ob_end_flush :发送内部缓冲区的内容到浏览器,并且关闭输出缓冲区。
使用方法:void ob_end_flush(void)
说明:这个函数发送输出缓冲区的内容(如果有的话)。
6、ob_end_clean:删除内部缓冲区的内容,并且关闭内部缓冲区
使用方法:void ob_end_clean(void)
说明:这个函数不会输出内部缓冲区的内容而是把它删除!
7、ob_implicit_flush:打开或关闭绝对刷新
使用方法:void ob_implicit_flush ([int flag])
说明:使用过Perl的人都知道$|=x的意义,这个字符串可以打开/关闭缓冲区,而ob_implicit_flush函数也和那个一样,默认为关闭缓冲区,打开绝对输出后,每个脚本输出都直接发送到浏览器,不再需要调用 flush()
例子:
ob_start();
echo "hello\n";
$c=ob_get_contents();
ob_end_flush();
echo "cache=".$c;
?>
输出:
hello
cache=hello
$t0=0;
$s0=0;
$t1=0;
$s1=0;
$t2=0;
$s2=0;
$t3=0;
$s3=0;
if (ob_get_level()){
$t0=1;
$s0=ob_get_level();
}
ob_start();
if (ob_get_level()){
$t1=1;
$s1=ob_get_level();
}
ob_start();
if (ob_get_level()){
$t2=1;
$s2=ob_get_level();
}
ob_start();
if ( ob_get_level()){
$t3=1;
$s3=ob_get_level();
}
ob_end_flush();
ob_end_flush();
ob_end_flush();
echo "t0=".$t0."\n";
echo "s0=".$s0."\n";
echo "t1=".$t1."\n";
echo "s1=".$s1."\n";
echo "t2=".$t2."\n";
echo "s2=".$s2."\n";
echo "t3=".$t3."\n";
echo "s3=".$s3."\n";
输出:
t0=0
s0=0
t1=1
s1=1
t2=1
s2=2
t3=1
s3=3
die( )
函数输出一条消息,并退出当前脚本。
该函数是 exit() 函数的别名。
语法
die(status)
参数 描述
status 必需。规定在退出脚本之前写入的消息或状态号。状态号不会被写入输出。
说明
如果 status 是字符串,则该函数会在退出前输出字符串。
如果 status 是整数,这个值会被用作退出状态。退出状态的值在 0 至 254 之间。退出状态 255 由 PHP 保留,不会被使用。状态 0 用于成功地终止程序。
file_exists()
文件是否存在,
is_readable()
文件是否可读
realpath()
绝对路径
extension_loaded()
是否安装了某模块
if(extension_loaded('pcre')){ } 是否安装了正则模块
require require_once include 区别
都是包含另一个php文件的意思。
require,require_once 的php文件必须存在,找不到则退出。
require与require_once 的区别
require_once 会做检查,看看前面是否已经引入了该php文件,若引入了则不再引入。
t.php
echo extension_loaded('pcre');
echo "\n";
require "aa.php";
require_once "aa.php";
echo "end\n";
?>
aa.php
echo "aa\n";
?>
执行 t.php
1
aa
end
isset unset var_dump
isset()
检测变量是否设置
unset()
释放变量
var_dump()
打印变量内存信息
$a=1;
if(isset($a)){
echo "0 isset\n";
}
var_dump($a);
unset($a);
if(isset($a)){
echo "1 isset\n";
}
输出
0 isset
int(1)
explode(split,str)
把字符串分割为数组
$str_a="a b c d e";
$arr_a=explode(' ',$str_a);
var_dump($arr_a);
结果
array(2) {
[0]=>
string(10) "0.89340000"
[1]=>
string(10) "1305184931"
}

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

AI Hentai Generator
Generate AI Hentai for free.

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

vue3+vite:src uses require to dynamically import images and error reports and solutions. vue3+vite dynamically imports multiple images. If vue3 is using typescript development, require will introduce image errors. requireisnotdefined cannot be used like vue2 such as imgUrl:require(' .../assets/test.png') is imported because typescript does not support require, so import is used. Here is how to solve it: use awaitimport

If you are an IT administrator or technology expert, you must be aware of the importance of automation. Especially for Windows users, Microsoft PowerShell is one of the best automation tools. Microsoft offers a variety of tools for your automation needs, without the need to install third-party applications. This guide will detail how to leverage PowerShell to automate tasks. What is a PowerShell script? If you have experience using PowerShell, you may have used commands to configure your operating system. A script is a collection of these commands in a .ps1 file. .ps1 files contain scripts executed by PowerShell, such as basic Get-Help

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

1. Java calls post interface 1. Use URLConnection or HttpURLConnection that comes with java. There is no need to download other jar packages. Call URLConnection. If the interface response code is modified by the server, the return message cannot be received. It can only be received when the response code is correct. to return publicstaticStringsendPost(Stringurl,Stringparam){OutputStreamWriterout=null;BufferedReaderin=null;StringBuilderresult=newSt

Usage of require: 1. Introduce modules: In many programming languages, require is used to introduce external modules or libraries so that the functions they provide can be used in the program. For example, in Ruby, you can use require to load third-party libraries or modules; 2. Import classes or methods: In some programming languages, require is used to import specific classes or methods so that they can be used in the current file; 3. Perform specific tasks: In some programming languages or frameworks, require is used to perform specific tasks or functions.

With the development of the Internet and the advancement of information technology, the era of big data has arrived, and fields such as data analysis and machine learning have also been widely used. In these fields, task scheduling is an inevitable problem. How to achieve efficient task scheduling is crucial to improving efficiency. In this article, we will introduce how to use Golang's web framework Echo framework to implement distributed task scheduling. 1. Introduction to the Echo framework Echo is a high-performance, scalable, lightweight GoWeb framework. It is based on HTTP

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets
