Putting a variable in a URL
-
Scenario:
A file is needing to be referenced in several places.
The name of this file changes often.
The folder where this file is remains the same, so I just want to alter the filename.So the link would normally be:
<a href="https://very/long/path/filename.txt">
This makes for messy editing and increased chance of mistakes. So…. I want to include a file with the name in and then include that in the url as a constant:
<?php include(‘constants.php’); ?>
and that has
$file1=rabbits.txt
$file2=carrots.txtThen in the main code body
<a href="https://very/long/path/<?php $file1 ?>">
Unsuprisingly (because I’m writing it) this does not work and when I view source I see
https://very/long/path/How do I do this ?
Thanks ??
- The topic ‘Putting a variable in a URL’ is closed to new replies.