Jump to content

Add name.php to include

Go to solution Solved by .josh,

Recommended Posts

 include ("../../../../../accounts/accounts/LINEAR LTD/PERIODIC/listofpdfs.php");


I have the above line of code and would like the company name, in this instance, LINEAR LTD,
to be replaced with file, name.php which contains the words LINEAR LTD.


It will save an enormous ammount of work as new clients are added.



Link to comment
Share on other sites

I suppose you could store the company names in a text file instead, each name on a new line. Then read in that text file into an array using the php function file(). Then you can loop through the variable that you assigned that to, and include all the files. I think that would work..

$names = file("names.txt");
foreach ($names as $name) {
    include "../".$name."/rest/of/path"; //Put your correct amount of ../ here
Edited by denno020
Link to comment
Share on other sites

  • Solution

One way:


name.php is a php file that sets a variable to be used on main.php




$name = 'LINEAR LTD';

include ("../../../../../accounts/accounts/{$name}/PERIODIC/listofpdfs.php");
Another way:


name.php is really just a text file with the name, and main.php retrieves its contents into a string





$name = trim(file_get_contents('name.php'));
include ("../../../../../accounts/accounts/{$name}/PERIODIC/listofpdfs.php");
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.