Home >Backend Development >PHP Tutorial >How to create a link in PHP

How to create a link in PHP

藏色散人
藏色散人Original
2019-01-21 16:16:164845browse

The website is full of links. You probably already know how to create links in HTML. If you have added PHP to your web server to enhance the functionality of your site, you may be surprised to know that the links created in PHP are the same as those created in HTML.

How to create a link in PHP

However, you have a few options. Depending on where the link is in the file, the link HTML may be displayed slightly differently.

You can switch back and forth between PHP and HTML in the same document, and you can use the same software (any plain text editor will do) to write PHP and write HTML.

How to add a link to a PHP document

If you are creating a link in a PHP document that is not inside PHP brackets, use HTML as usual.

Examples are as follows:

<a href="http://www.php.cn/">My PHP</a>
<?php
----- My PHP Code----
?>

If the link needs to be in PHP, there are two options. One option is to end PHP, enter the link in HTML, and reopen PHP.

Examples are as follows:


<a href="http://www.php.cn/">My PHP</a>
<?php
----- My PHP Code----
?>

Another option is to print or echo the HTML code in PHP.

Examples are as follows:

<?php
Echo "<a href=http://www.php.cn/>My PHP</a>"
?>

Another thing you can do is create links from variables. Let's say the variable $url holds the url of a website that someone submitted or that you pulled from a database.

You can use this variable in HTML.

<a href="http://www.php.cn/">My PHP</a>
<?php
Echo "<a href=$url>$site_title</a>"
?>

For junior PHP programmers

If you are not familiar with PHP, please remember to use 0f638c78331fd98063352e70b7876245Start and end a block of PHP code. This code lets the server know that the included content is PHP code.

The above is the detailed content of How to create a link in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more