Jump to content

Add name.php to include


grucker

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
https://forums.phpfreaks.com/topic/285877-add-namephp-to-include/
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
}

One way:

 

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

 

name.php

 

<?php
$name = 'LINEAR LTD';
?>
main.php

include("name.php");
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.php

 

LINEAR LTD
main.php

$name = trim(file_get_contents('name.php'));
include ("../../../../../accounts/accounts/{$name}/PERIODIC/listofpdfs.php");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.