grucker Posted February 2, 2014 Share Posted February 2, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/285877-add-namephp-to-include/ Share on other sites More sharing options...
doddsey_65 Posted February 2, 2014 Share Posted February 2, 2014 Sounds like a good idea. Was there a question? Quote Link to comment https://forums.phpfreaks.com/topic/285877-add-namephp-to-include/#findComment-1467435 Share on other sites More sharing options...
denno020 Posted February 2, 2014 Share Posted February 2, 2014 (edited) 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 February 2, 2014 by denno020 Quote Link to comment https://forums.phpfreaks.com/topic/285877-add-namephp-to-include/#findComment-1467436 Share on other sites More sharing options...
Solution .josh Posted February 2, 2014 Solution Share Posted February 2, 2014 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"); Quote Link to comment https://forums.phpfreaks.com/topic/285877-add-namephp-to-include/#findComment-1467445 Share on other sites More sharing options...
grucker Posted February 2, 2014 Author Share Posted February 2, 2014 Thank you, both suggestions work perfectly well. I used the second method. Quote Link to comment https://forums.phpfreaks.com/topic/285877-add-namephp-to-include/#findComment-1467450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.