PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
On that page I also have links A - Z and when each one is clicked I want to display the other include files hosts-b.html to hosts-z.html
I think I need to use an if statement but how do I use the link to load the relevant include file - ie they click on the B link and hosts-b.html is displayed in place of where the include hosts-a.html was? The web page is here if needed http://www.hgtsa.com.au/hostemployers/index.php
I wouldn't do it manually. Something with a regex match would be the most efficient (from a programming and maintenance standpoint, anyway) way to accomplish this...
Thank you for the reply. No wonder I couldn't get it working - I wasn't even at the right station let alone being on the right track.
As a complete newbie with just basic experience this code is a tad over my head.
Do I just add this in to my page where I currently have <?php include('includes/hosts-a.html'); ?>?
Is there anything else I need to do with my page elsewhere eg what do I do with the navigation links which are currently pointing to 26 separate pages <a href="../hostemployers/hostemployers-b.php">B</a> each with its own include.
tasairas - thank you as well for your help with this. I thought the code would be easier than this and both replies are way out of my depth. Is there any chance you could elaborate for me on your code on what to put in my links - currently <a href="../hostemployers/hostemployers-b.php">B</a> but I want these to load the includes instead of going to a separate page?
$link_variable = substr($link_variable . "0", 0, 1);
$path = dirname(__FILE__) . "/include/hosts-{$link_variable}.html";
if ($link_variable >= "a" && $link_variable <= "z" && is_file($path)) {
include $path;
}
That's fine if you want to make assumptions about the input and abandon error handling, which are common problems in the PHP community... personally, I would rather write something more "complicated" that handles input without modifying it and provides accurate error handling so it can be debugged and monitored correctly.
I would not call anything using integer operations to compare strings arbitrarily concatenated to ignore the actual input good practice or even suitable for production. This is inaccurate and basically an incorrect result by design.