0

I want to to require only the (functions, classes, variables) from another PHP file but that file have some html content which I don't want.

I already tried require, include, INCLUDE_ONCE, REQUIRE_ONCE but none worked

2
  • I would go with best practices, and don't include the HTML directly in the PHP file in the first place. Or if you absolutely must, move all of the functions/classes/variables into a single PHP file and call it functions.php and just include that where it is needed. Commented Aug 31, 2020 at 19:04
  • 1
    Create a file with the functions and without the HTML. Then include that. Commented Aug 31, 2020 at 19:05

1 Answer 1

4

As the comments suggested, the best way is to reorganize the code so you don't mix functions and HTML in the include file.

But if you really need to do this, you can do it with the output buffering functions.

ob_start();
require 'filename.php';
ob_end_clean();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.