Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including PHP functions from another file

Tags:

function

php

I would like to access some functions defined in another PHP file, but that file also outputs content that I don't want to display.

Is there any way to access the functions without "running" the whole file? Perhaps by redirecting the output from that file to somewhere hidden?

like image 282
Will Avatar asked Jan 21 '26 01:01

Will


2 Answers

<?php
ob_start();
require 'filename.php';
ob_end_clean();
?>
like image 71
KARASZI István Avatar answered Jan 23 '26 14:01

KARASZI István


Eh you might be able to do something with using the output buffer and manually clearing contents, but why not just move the common functions into a common include? I usually shove common helper methods into their own file (which won't output anything).

like image 41
Parrots Avatar answered Jan 23 '26 14:01

Parrots



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!