简体   繁体   English

将变量作为 href 显示的文本传递

[英]Pass a variable as the text shown by an href

I am making a front end for a database of books and their writers.我正在为书籍及其作者的数据库制作前端。 I can list them by genre so that you can more easily find them and on that page there are hyperlinks so that you can update and add chapters of the books.我可以按流派列出它们,以便您可以更轻松地找到它们,并且在该页面上有超链接,以便您可以更新和添加书籍的章节。

I now want to give each hyperlink the same name as the book it refers to, but I can't figure out how to give an href a variable name.我现在想为每个超链接指定与其引用的书相同的名称,但我不知道如何为 href 指定一个变量名。

I thought it would be possible this way, but it clearly isn't.我认为这种方式是可能的,但显然不是。

<td><a href="update_book_chapters.php?book_uri=http://dbpedia.org/resource/" . $bookName>$bookName</a></td>

Can anybody tell me whether it is possible to give an href a variable display name and if it is possible: how?任何人都可以告诉我是否可以给 href 一个变量显示名称,如果可能的话:如何?

If that single line you posted is from some html template, then this is probably what you are looking for:如果您发布的那一行来自某个 html 模板,那么这可能就是您要查找的内容:

<td>
    <a href="update_book_chapters.php?book_uri=http://dbpedia.org/resource/<?php echo urlencode($bookName) ?>">
        <?php echo htmlentities($bookName) ?>
    </a>
</td>

Depending on your php setup you might be able to use this more compact syntax:根据您的 php 设置,您可能可以使用这种更紧凑的语法:

<td>
    <a href="update_book_chapters.php?book_uri=http://dbpedia.org/resource/<?= urlencode($bookName) ?>">
        <?= htmlentities($bookName) ?>
    </a>
</td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM