2018-6-28-PHP几个牛逼的函数

layouttitledateauthordescin_head
post
PHP几个牛逼的函数
2018-6-28- 10:00:02 +0800
南丞
PHP牛逼的函数介绍
<style> .article-content p{ text-indent: 2em; line-height: 1.75rem; }</style>

PHP几个牛逼的函数

  • get_included_files()get_required_files()

    返回被 include 和 require 文件名的 array

<?php
    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:\phpStudy\WWW\test.php:7:
    array (size=4)
    0 => string 'D:\phpStudy\WWW\test.php' (length=24)
    1 => string 'D:\phpStudy\WWW\1.php' (length=21)
    2 => string 'D:\phpStudy\WWW\i.php' (length=21)
    3 => string 'D:\phpStudy\WWW\2.php' (length=21)
    D:\phpStudy\WWW\test.php:9:string '.;C:\php\pear' (length=13)
    D:\phpStudy\WWW\test.php:10:
    array (size=4)
    0 => string 'D:\phpStudy\WWW\test.php' (length=24)
    1 => string 'D:\phpStudy\WWW\1.php' (length=21)
    2 => string 'D:\phpStudy\WWW\i.php' (length=21)
    3 => string 'D:\phpStudy\WWW\2.php' (length=21)
  • php_check_syntax()

    用来检查特定文件中的PHP语法是否正确。

<?php
    $error_message = "";
    $filename = "./php_script.php";
    if(!php_check_syntax($filename, &$error_message)) {
    echo "Errors were found in the file $filename: $error_message";
    } else {
    echo "The file $filename contained no syntax errors";
    }
    ?>
  • highlight_string()show_source(),php_strip_whitespace()

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

<?php
    highlight_string(' <?php phpinfo(); ?>');
    show_source("php_script.php");
    echo php_strip_whitespace("php_script.php");
?>
  • str_word_count()

这个函数可以用来统计字符串中单词的数量。

<?php
echo str_word_count("Hello How Are You!");

  • get_defined_vars()

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

<?php
print_r(get_defined_vars());

  • checkdate()

验证一个格里高里日期

<?php

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值