Home > Article > Backend Development > interesting! Set PHP variable to anchor text in HTML
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
As shown in our file First create a variable. PHP variables are "containers" used to store information:
<?php $var = 'PHP教程'; ?>
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="//m.sbmmt.com">学习<?php echo $var; ?></a></p> </body> </html>
Do you want to know what will happen if you run this code? What effect occurs?
Please look at the picture below:
Click "Learn PHP Tutorial" here to jump to the specified link.
And the variables in the title are also displayed, as shown below:
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!