modify code to combine certian php files to one

The code below combines every .php file it finds in a directory. I need help to modify it so I can tell it what php files to combine.

(ie: Need to combine the following pages, page1.php, page2.php, page3.php, page4.php, page5.php, page6.php,
page7.php, page8.php, page9.php, page10.php, page11.php, page12.php )

Thanks in advance.

[php]

<?php foreach (glob("*.php") as $filename) { $code.=file_get_contents("./$filename"); } file_put_contents("./combined.php",$code); ?>

[/php]

You’ll need to clarify a bit more, what you’re asking makes no sense to anyone but you.

I re-worded it. I’m not sure how else to change it. I only need help with current code to have it modified to allow me to put what files I want combined.

Why do you need to combine php files together? That’s generally illogical. There’s a fairly easy way to do this but no matter how you do it, you’ll need to make the order of inclusion specific to the content flow of the files it’s combining. Cause remember that php reads top-to-bottom and if you combine the pages out of order, you’ll get a ton of errors in the script of those pages.

Because I decided to have the pages created on the fly and I wanted the information submitted hard coded and to avoid using 20 or more includes that end up clashing with a few hundred or more since php doesn’t do well with subdirectories when pages are called form another php on the same machine.

If I could delete the question I would.

I already marked it as solved. I already found the code that worked.

[php]

<?php $txt1 = file_get_contents('page-001.php'); $txt1 .= "\n" . file_get_contents('page-002.php'); $txt1 .= "\n" . file_get_contents('page-003.php'); $txt1 .= "\n" . file_get_contents('page-004.php'); $txt1 .= "\n" . file_get_contents('page-005.php'); $txt1 .= "\n" . file_get_contents('page-006.php'); $txt1 .= "\n" . file_get_contents('page-007.php'); $txt1 .= "\n" . file_get_contents('page-008.php'); $txt1 .= "\n" . file_get_contents('page-009.php'); $txt1 .= "\n" . file_get_contents('page-010.php'); $txt1 .= "\n" . file_get_contents('page-011.php'); $txt1 .= "\n" . file_get_contents('page-012.php'); $fp = fopen('newcombined.php', 'w'); if(!$fp) die('Could not create / open text file for writing.'); if(fwrite($fp, $txt1) === false) die('Could not write to text file.'); echo 'Text files have been merged.'; ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service