(如何)我可以将 HREF 链接到 PHP 生成网页中的锚点吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16868555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
(How) can I link an HREF to an anchor within a PHP generate web page?
提问by Mawg says reinstate Monica
I use PHP to generate my web site. I would like to add a link to an anchor within a .PHP page.
我使用 PHP 来生成我的网站。我想在 .PHP 页面中添加一个指向锚点的链接。
(How) can I do that?
(我怎样才能做到这一点?
回答by Ben
Basic HTML:
基本 HTML:
<a href='#targetanchor'>Linking from here</a>
...
<a id='targetanchor'>Linking to here</a>
Just echo it out in your PHP.
只需在您的 PHP 中将其回显即可。
I think you can use ID or name for the target identifier, may be browser-dependent though.
我认为您可以使用 ID 或名称作为目标标识符,但可能取决于浏览器。
Of course, that's an anchor in the same page. To do it to a specific place in another page, put in the address:
当然,这是同一页面中的锚点。要在另一个页面的特定位置执行此操作,请输入地址:
<?php
echo "<a href='whatever.php#targetanchor>Jump to target on whatever</a>";
?>
Re-reading your question, you may be asking if an anchor can be added with a link to a PHP page.
重新阅读您的问题,您可能会问是否可以添加带有指向 PHP 页面链接的锚点。
Of course it can. The PHP part is just the language that the server is instructed to interpet the page in. Then it sends regular HTML back to the client browser, who uses the anchors to jump around the HTML document.
当然可以。PHP 部分只是服务器被指示插入页面的语言。然后它将常规 HTML 发送回客户端浏览器,客户端浏览器使用锚点在 HTML 文档中跳转。
回答by web2students.com
If you want html within php, best way is to separate html and php like,
如果您想在 php 中使用 html,最好的方法是将 html 和 php 分开,例如,
<?php
//some php code
?>
<!--html content -->
If there is small html within php then you can do like,
如果 php 中有小 html,那么你可以这样做,
<?php
echo '<b>Bold stuff</b>';
?>
If there is mixing of lot of html and php, then use heredoc, http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
如果有很多 html 和 php 的混合,那么使用 heredoc,http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc