Mustafa Mansoor
Mustafa Mansoor

Reputation: 177

How do I to include a file in php without using include or require?

How do I call a function which is in a different file without including or requiring that file?

Upvotes: 4

Views: 3457

Answers (3)

David Fells
David Fells

Reputation: 6798

You can't. If you don't include or require it, PHP has no idea what's there. You can use .htaccess or php.ini to automatically include a file, which is identical to including it with require or include.

For example in .htaccess

php_value auto_prepend_file "/full/path/to/a/prepend-file.php"

In php.ini

  auto_prepend_file = "/full/path/to/a/prepend-file.php"

Upvotes: 5

Schwern
Schwern

Reputation: 165606

Read it into a string and eval it.

$code = file_get_contents("somefile.php");
eval($code);

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799550

Copy and paste it. But mind the license.

Upvotes: 0

Related Questions