我刚刚将一些HTML
页面转换为PHP
页面,对PHP
不太熟悉。在我的HTML
页面中,假设它只是一个静态的web应用程序,我可以通过在页面上播放以下anchor
来链接到另一个页面:
<a href="go-to-this-page.html">This is a link</a>
因此,在将页面转换为PHP
之后,为了确保我可以更容易、更快地模板化和包含模板,我不知道如何包含这些链接。
例如,假设我有两个页面,index.php
和page2.php
。如何创建指向此页面的锚链接?
<a href="??????">This is a link</a>
像这样使用
<a href="index.php">Index Page</a>
<a href="page2.php">Page 2</a>
最简单:
<a href="page2.php">Link</a>
如果你需要传递一个值:
<a href="page2.php?val=1">Link that pass the value 1</a>
要检索page2.php中的值,请执行以下代码:
<?php
$val = $_GET["val"];
?>
现在,变量$val
具有值1
。
Html标签
html 中的链接
<a href="index1.php">page1</a>
<a href="page2.php">page2</a>
php 中的Html
echo ' <a href="index1.php">page1</a>';
echo '<a href="page2.php">page2</a>';
echo "<a href='index.php'>Index Page</a>";
如果你想使用像锚标签一样的html标签,你必须放在echo 中
就这样试试吧:
PHP中的HTML:
$link_address1 = 'index.php';
echo "<a href='".$link_address1."'>Index Page</a>";
$link_address2 = 'page2.php';
echo "<a href='".$link_address2."'>Page 2</a>";
最简单的
$link_address1 = 'index.php';
echo "<a href='$link_address1'>Index Page</a>";
$link_address2 = 'page2.php';
echo "<a href='$link_address2'>Page 2</a>";
您也可以像这样使用
<a href="<?php echo 'index.php'; ?>">Index Page</a>
<a href="<?php echo 'page2.php'; ?>">Page 2</a>