Insert php variable in a href

后端 未结 4 1365
青春惊慌失措
青春惊慌失措 2020-12-09 12:11

I am planning to insert a PHP variable which holds the directory path for a file stored on my Windows machine. How can I include this variable in the a href tag

相关标签:
4条回答
  • 2020-12-09 12:46

    You could try:

    <a href="<?php echo $directory ?>">The link to the file</a>
    

    Or for PHP 5.4+ (<?= is the PHP short echo tag):

    <a href="<?= $directory ?>">The link to the file</a>
    

    But your path is relative to the server, don't forget that.

    0 讨论(0)
  • 2020-12-09 12:55
    echo '<a href="' . $folder_path . '">Link text</a>';
    

    Please note that you must use the path relative to your domain and, if the folder path is outside the public htdocs directory, it will not work.

    EDIT: maybe i misreaded the question; you have a file on your pc and want to insert the path on the html page, and then send it to the server?

    0 讨论(0)
  • 2020-12-09 12:58

    Try using printf function or the concatination operator

    http://php.net/manual/en/function.printf.php

    0 讨论(0)
  • 2020-12-09 13:02

    in php

    echo '<a href="' . $folder_path . '">Link text</a>';
    

    or

    <a href="<?=$folder_path?>">Link text</a>;
    

    or

    <a href="<?php echo $folder_path ?>">Link text</a>;
    
    0 讨论(0)
提交回复
热议问题