Home > Backend Development > PHP Tutorial > interesting! Set PHP variable to anchor text in HTML

interesting! Set PHP variable to anchor text in HTML

藏色散人
Release: 2023-04-10 12:26:01
Original
2602 people have browsed it

How to set PHP variable as anchor text in HTML? Hyperlink? Friends, do you have any ideas for realizing this problem? First of all, everyone should know that PHP, as a common language for web development, can also be embedded in HTML. So this kind of problem is probably not worth mentioning for the big guys, because it is too simple, but the cute novices can stay and learn~

Now I will teach you step by step how to do it ImplementationSet PHP variables to anchor text in HTML.

First of all, after the PHP environment has been set up, let's create a new PHP file. I named it demo.php

interesting! Set PHP variable to anchor text in HTML

As shown in our file First create a variable. PHP variables are "containers" used to store information:

<?php
$var = &#39;PHP教程&#39;;
?>
Copy after login

Then create an HTML structure:

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title><?php echo $var; ?> - php.cn!</title>
</head>
<body>
<h3><?php echo $var; ?></h3>
<p>PHP即“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。</p>
<p><a href="https://www.php.cn">学习<?php echo $var; ?></a></p>
</body>
</html>
Copy after login

Do you want to know what will happen if you run this code? What effect occurs?

Please look at the picture below:

interesting! Set PHP variable to anchor text in HTML

Click "Learn PHP Tutorial" here to jump to the specified link.

And the variables in the title are also displayed, as shown below:

interesting! Set PHP variable to anchor text in HTML

Done! ! ! Isn’t it interesting!

You might as well try it locally~

Finally, let me introduce to you the rules of PHP variables:

  • Variables start with $ symbol, followed by the name of the variable

  • Variable names must begin with letters or underscore characters

  • Variable names can only contain alphanumeric characters and Underscores (A-z, 0-9 and _)

  • Variable names cannot contain spaces

  • Variable names are case-sensitive ($y and $Y are two different variables)

PHP Chinese website has many free and high-quality PHP video tutorials, welcome to learn!

The above is the detailed content of interesting! Set PHP variable to anchor text in HTML. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template