How to combine multiple html files (with PHP and JS code in them) into one big html file

I am trying to create a script that will receive several HTML files that could have PHP code in them and JavaScript code and make a large HTML / PHP file with it. For example, home.php, news.php, something.php Will be combined to form Index.php.

Before anyone asks why I need a file like this: the reason is to create 1 file that uses a responsive touchscreen layout using parallax.

I tried file_get_contents()

but if the html has a simple <?php echo "hello world";?>

one it won't output it.

How can I combine multiple HTML files with anything in them (JS, php, etc.)?

+3


source to share


2 answers


If you want unexplored PHP code, you need an FTP connection to PHP files. Using cURL, you will open an FTP connection and download the file, which will be in its original form from <?php echo "hello world"; ?>

, etc. It's like using a regular FTP client on your operating system to fetch a file, in which case it will be in a variable in your PHP script, then you can execute the content or do whatever from there.



Of course this method also depends on whether the host (server) allows it.

+2


source


Have you tried include ()? This should work fine.

From PHP docs ... http://php.net/manual/en/function.include.php



The include statement includes and evaluates the specified file.

+2


source







All Articles