如何在由php中的斜杠分隔的锚中回显正确的2个变量

如何在由php中的斜杠分隔的锚中回显正确的2个变量

问题描述:

I have this variable: $dir = 'uploads/sfm/'.$UserID;

$file represents a file (like image.jpg)

What is the correct way to echo an anchor in which these 2 variables seperated by a / ?

Below is how i do it now and it does work fine but i think this is not the correct way to do it:

echo "<a href='$dir/$file' target='_blank'></a>";

try this

echo '<a href="' . $dir.'/' . $file.'" target="_blank"></a>';

or this

<a target="_blank" href="<?php echo $dir .'/'. $file; ?>"></a>

I would have done like this :

echo "<a href='" . $dir . "/" . $file . "' target='_blank'></a>";