How to create a link to another PHP page

2019-03-30 05:22发布

I just converted some of my HTML pages to PHP pages, and I'm not that familiar with PHP. In my HTML pages, assuming it's just a static web app, I can link to another page quite simply by playing the following anchor on the page:

<a href="go-to-this-page.html">This is a link</a>

So, after converting the pages to PHP in order to make sure that I can template and include templates a bit easier and faster, I don't know how to include these links.

For example, say I have two pages, index.php and page2.php. How would I create an anchor link to this page?

<a href="??????">This is a link</a>

Thanks for any help!

6条回答
smile是对你的礼貌
2楼-- · 2019-03-30 05:37

Just try like this:

HTML in PHP :

$link_address1 = 'index.php';
echo "<a href='".$link_address1."'>Index Page</a>";

$link_address2 = 'page2.php';
echo "<a href='".$link_address2."'>Page 2</a>";

Easiest way

$link_address1 = 'index.php';
echo "<a href='$link_address1'>Index Page</a>";

$link_address2 = 'page2.php';
echo "<a href='$link_address2'>Page 2</a>";
查看更多
我想做一个坏孩纸
3楼-- · 2019-03-30 05:38

Easiest:

<a href="page2.php">Link</a>

And if you need to pass a value:

<a href="page2.php?val=1">Link that pass the value 1</a>

To retrive the value put in page2.php this code:

<?php
$val = $_GET["val"];
?>

Now the variable $val has the value 1.

查看更多
趁早两清
4楼-- · 2019-03-30 05:49

You can also used like this

<a href="<?php echo 'index.php'; ?>">Index Page</a>
<a href="<?php echo 'page2.php'; ?>">Page 2</a>
查看更多
甜甜的少女心
5楼-- · 2019-03-30 05:50

Use like this

<a href="index.php">Index Page</a>
<a href="page2.php">Page 2</a>
查看更多
看我几分像从前
6楼-- · 2019-03-30 05:52
echo "<a href='index.php'>Index Page</a>";

if you wanna use html tag like anchor tag you have to put in echo

查看更多
爷的心禁止访问
7楼-- · 2019-03-30 06:00

Html a tag

Link in html

 <a href="index1.php">page1</a>
 <a href="page2.php">page2</a>

Html in php

echo ' <a href="index1.php">page1</a>';
echo '<a href="page2.php">page2</a>';
查看更多
登录 后发表回答