Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP require_once() .js file

Okay, so I'm using require_once to load the contents of a .js file. However, there seems to be a 1 added to the end of the file after the require is done.

PHP:

echo require_once("test.js");

JS:

var newFunc = function() {
    console.log('yay!');
};

rendered html when the PHP file is loaded:

var newFunc = function() {
    console.log('yay!');
};1
like image 935
CJT3 Avatar asked Apr 14 '26 04:04

CJT3


1 Answers

require_once() returns 1 if the include was successful. So you're echoing the return value, which is not what you thought it was.

Use file_get_contents() instead, although this is odd usage, you're probably heading in the wrong direction with whatever you're trying to do with this...

like image 50
i-CONICA Avatar answered Apr 16 '26 17:04

i-CONICA



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!