1. 文章
  2. 文章详情

PHP一些有用的函数

get_included_files() 和 get_required_files() (PHP 4, PHP 5, PHP 7)

返回所有被 include、 include_once、 require 和 require_once 的文件名。

返回所有文件名称的 array。

脚本最初被称为”被包含的文件“,所以脚本自身也会和 include 系列函数引用的脚本列在一起。

被多次 include 和 require 的文件在返回的 array 里只会列出一次。

include'./1.php';     
include'./i.php';     
require'./2.php';      
$files = get_included_files();     
var_dump($files);     
$files_list = get_include_path();     
var_dump($files_list);     
var_dump(get_required_files());

结果:

D:phpStudyWWWtest.php:7:    
 array (size=4)    
            0 => string 'D:phpStudyWWWtest.php' (length=24)     
            1 => string 'D:phpStudyWWW1.php' (length=21)     
            2 => string 'D:phpStudyWWWi.php' (length=21)     
            3 => string 'D:phpStudyWWW2.php' (length=21)     
D:phpStudyWWWtest.php:9:string '.;C:phppear' (length=13)     
D:phpStudyWWWtest.php:10:     
             array (size=4)     
                 0 => string 'D:phpStudyWWWtest.php' (length=24)     
                 1 => string 'D:phpStudyWWW1.php' (length=21)     
                 2 => string 'D:phpStudyWWWi.php' (length=21)     
                 3 => string 'D:phpStudyWWW2.php' (length=21)

highlight_string() 和 show_source(),php_strip_whitespace()

把PHP代码显示到页面上时,highlight_string()函数就会非常有用,它可以用内置定义的语法高亮颜色把你提供的PHP代码高亮显示。

highlight_string(' ');     
show_source("php_script.php");     
echo php_strip_whitespace("php_script.php"); 

str_word_count()

用来统计字符串中单词的数量。

 echo str_word_count("Hello How Are You!");

get_defined_vars()

这个函数在代码调试时十分重要,它会返回一个包括所有已定义的变量的多维数组。

 print_r(get_defined_vars());

checkdate()

验证一个格里高里日期

var_dump(checkdate(12, 31, 2000));     
var_dump(checkdate(2, 29, 2001));

发表评论

登录后才能评论

评论列表(0条)