-1

I am working on a site and the builders have used a mix of php and html for links. For example:

<li><a href="variable-frequency-drives.php">Variable Speed Drives</a></li>
<li><a href="corrosion-resistant-baseplates.php">Corrosion Resistant Baseplates</a></li>

and

<li><a href="<?php echo $external_video_link?>MP_PUMP.html" target="_blank">MP Repair</a></li>
<li><a href="<?php echo $external_video_link?>MTA_PUMP.html" target="_blank">MTA Repair</a></li>

The php is referenced in another file in this way:

<?php 
$pdf_link = "../pdf/";
$external_pdf_link = "../../pdf/";
$video_link = "../video/";
$external_video_link = "../../video/";
?>

My concern is not knowing the function of the php, other than it being a placeholder, and given that the links work both ways, I don't want to break something because I am clueless to its purpose.

In doing my due diligence researching, I ran across this post, which is close, but still no cigar, Add php variable inside echo statement as href link address?. All of the research seems to be about how rather than why. This is the site, and they only used it for the "Downloads" links: http://magnatexpumps.com/

Thank you... B

TexasB
  • 85
  • 1
  • 12
  • I don't understand what it is that you're asking. Your example is just a basic variable substitution. ` – j08691 Mar 21 '18 at 20:03
  • 4
    The usual purpose for doing this is so that if you want to change all your links to point somewhere else, you only have to edit one line. – Alex Howansky Mar 21 '18 at 20:05
  • @AlexHowansky That does offer an explanation I had not thought of. I see that it is a substitution but not being completely versed in php I was looking for exactly that, something I had not seen before. – TexasB Mar 21 '18 at 20:28

1 Answers1

1

There is no right way. They are just different.

Let's forget the PHP for a while. If you have this link in a page:

<a href='about.html'/>About</a>

What will happen? The browser will change the URL of the document. If you are at the root of the site like: "www.example.com", will redirect to "www.example.com/about.html". If you are in a URL like "www.example.com/news/index.html" will redirect you to "www.example.com/new/about". That's why sometimes it is useful to have a variable before, to force a full path URL.

Another case of URL variable interpolation is when you have different systems running in the same url. In this case, you will have to append the system name in order to get to where you want. If you don't know where your application will run if it will run on the doc root, or in a subfolder, use a variable to indicate the base path.

Paulo Lima
  • 65
  • 1
  • 6
  • Paulo, I appreciate the considerate insight. Given that the site isn't deeper than two sub-folders I didn't think about the points that you brought up. And I appreciate knowing that things won't break either way. – TexasB Mar 21 '18 at 20:35