using PHP variables in html tag

后端 未结 6 682
臣服心动
臣服心动 2021-01-14 04:32

I get a variable from PHP code which is a webpage link, and want to use that in html tag. For example:

api();         


        
相关标签:
6条回答
  • 2021-01-14 05:00

    You must echo the value ... also, don't forget to escape it:

    <a href="<?php echo htmlspecialchars($link, ENT_QUOTES, 'UTF-8'); ?>">LINK</a>
    

    Since PHP 5.4 it's also safe to use short open tags:

    <a href="<?= htmlspecialchars($link, ENT_QUOTES, 'UTF-8'); ?>">LINK</a>
    
    0 讨论(0)
  • 2021-01-14 05:05

    if you have html file then fist change the extention .php in place of .html

    eg. you have test.html then change that to test.php

    after that you use the same code as

    <?php $link='http://stackoverflow.com' ?>
    
    <a href= "<?php echo $link; ?>" > LINK </a>
    

    Hope this will help you

    0 讨论(0)
  • 2021-01-14 05:06

    Try this :

    <a href= "<?php echo $link; ?>" > LINK </a>
    

    echo it echo $link;

    Alternatively, short hand would be:

    <a href= "<?= $link; ?>" > LINK </a>
    
    0 讨论(0)
  • 2021-01-14 05:14

    Or in short way:

    <a href="<?= $link; ?>">LINK</a>
    
    0 讨论(0)
  • 2021-01-14 05:16

    this is work for me you have to call the function (echo) in HTML Tag ... that all , good luck.

    enter <a href= "<?php echo $link; ?>" > LINK </a> here
    
    0 讨论(0)
  • 2021-01-14 05:24
    <a href= "<?php echo $link; ?>" > LINK </a>
    

    or

    <?php
    
    echo '<a href= "'.$link.'"> LINK </a>';
    
    ?>
    
    0 讨论(0)
提交回复
热议问题