仅在文件存在时如何包括 [英] How to include only if file exists

查看:51
本文介绍了仅在文件存在时如何包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个include函数/语句,该函数/语句仅在文件存在时才包含该文件. PHP中有一个吗?

I need an include function / statement that will include a file only if it exists. Is there one in PHP?

您可能会建议使用@include,但是这种方法存在问题-如果要包含的文件存在,如果解析器在包含的文件中发现错误,PHP将不会输出警告.

You might suggest using @include but there is an issue with that approach - in case the file to be included exists, PHP will not output warnings if the parser find something wrong in the included file.

推荐答案

if(file_exists('file.php'))
    include 'file.php';

那应该做你想要的

这篇关于仅在文件存在时如何包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆