feacco
feacco

Reputation: 605

php function same as "include" but don't shows warning

I don't know PHP well but also I don't want to stop error reporting.

Please tell me a function which won't display errors or warnings when the file is not found but otherwise works the same as the include function, e.g.

<?php include("file.txt"); ?>

Upvotes: 0

Views: 49

Answers (2)

Repox
Repox

Reputation: 15476

This question should be solved in a way that makes sense, instead of suppressing errors and warnings.

A better way of doing this would be something like:

$include_file = "file.txt";
if( file_exists($include_file) && is_readable($include_file) ) {
    include $include_file;
}

Upvotes: 0

user2899728
user2899728

Reputation: 2319

You can add @ in the beginning of this function to hide warning e.g.

<?php @include("file.txt"); ?> 

This way you will not see warning for only this line of code.

Upvotes: 1

Related Questions