Home > Article > Backend Development > Some basic tags for PHP learning
This article mainly introduces some basic tags about PHP learning, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
The $ symbol in 1.php is a variable symbol; add the $ symbol to a string, and the string is a variable name or object name.
2.echo is the output symbol
The meaning of directly outputting characters or strings: For example: echo "abc"; will output abc. echo 'abc' will also output abc. If only a string is output, the output content of single quotes and double quotes is the same. If you want to output a string variable, for example, the string variable $a='abc'; echo "$a123" will output abc123, but if you use echo '$a123', only $a123 will be output, that is to say, the value in single quotes The content will be output as is, and the double quotes will determine whether there are variables in it. If there are variables, they will be converted into the values of the variables.
3.What is COOKIE?
Cookies are often used to identify users. A cookie is a small file that a server leaves on a user's computer. Each time the same computer requests a page through the browser, the cookie will be sent to the computer. With PHP, you can create and retrieve cookie values.
The setcookie() function is used to set cookies.
Note: setcookie() function must be located before the 100db36a723c770d327fc0aef2ce13b1 tag.
setcookie(name, value, expire, path, domain);
In the following example, we will create a cookie named "user" and assign it the value "runoob". We also specify that this cookie expires after one hour:
<?php setcookie("user", "runoob", time()+3600);?><html>.....
Note: The cookie value is automatically URL-encoded when sending the cookie and automatically decoded when retrieved. (To prevent URL encoding, use setrawcookie() instead.)
You can also set the cookie expiration time in another way. This may be simpler than using seconds.
<?php $expire=time()+60*60*24*30;setcookie("user", "runoob", $expire);?><html>.....
In the above example, the expiration time is set to one month (60 seconds * 60 minutes * 24 hours * 30 days).
PHP’s $_COOKIE variable is used to retrieve the value of the cookie.
In the following example, we retrieve the value of the cookie named "user" and display it on the page:
<?php// 输出 cookie 值echo $_COOKIE["user"];// 查看所有 cookieprint_r($_COOKIE);?>
In the following example, we use isset() function to confirm whether the cookie has been set:
<html><head><meta charset="utf-8"><title>菜鸟教程(runoob.com)</title></head><body><?phpif (isset($_COOKIE["user"])) echo "欢迎 " . $_COOKIE["user"] . "!<br>";else echo "普通访客!<br>";?></body></html>
当删除 cookie 时,您应当使过期日期变更为过去的时间点。
删除的实例:
<?php// 设置 cookie 过期时间为过去 1 小时setcookie("user", "", time()-3600);?>
如果您的应用程序需要与不支持 cookie 的浏览器打交道,那么您不得不使用其他的办法在您的应用程序中的页面之间传递信息。一种方式是通过表单传递数据(有关表单和用户输入的内容,在本教程的前面章节中我们已经介绍过了)。
下面的表单在用户单点击 "Submit" 按钮时,向 "welcome.php" 提交了用户输入:
<html><head><meta charset="utf-8"><title>菜鸟教程(runoob.com)</title></head><body><form action="welcome.php" method="post">名字: <input type="text" name="name">年龄: <input type="text" name="age"><input type="submit"></form></body></html>
取回 "welcome.php" 文件中的值,如下所示:
<html><head><meta charset="utf-8"><title>菜鸟教程(runoob.com)</title></head><body>欢迎 <?php echo $_POST["name"]; ?>.<br>你 <?php echo $_POST["age"]; ?> 岁了。</body></html>
4. HTML 3499910bf9dac5ae3c52d5ede7383485 标签的 href 属性
HTML 3499910bf9dac5ae3c52d5ede7383485 标签
href 属性规定链接的目标:
c11a6a07e7cabbc95a86cad4099c8799W3School5db79b134e9f6b82c0b36e0489ee08ed
亲自试一试
3499910bf9dac5ae3c52d5ede7383485 标签的 href 属性用于指定超链接目标的 URL。
href 属性的值可以是任何有效文档的相对或绝对 URL,包括片段标识符和 JavaScript 代码段。如果用户选择了 3499910bf9dac5ae3c52d5ede7383485 标签中的内容,那么浏览器会尝试检索并显示 href 属性指定的 URL 所表示的文档,或者执行 JavaScript 表达式、方法和函数的列表。
注意:3499910bf9dac5ae3c52d5ede7383485 标签中必须提供 href 属性或 name 属性。
一个引用其他文档的简单 3499910bf9dac5ae3c52d5ede7383485 标签可以是下列形式:
eaadad625ac430c8516a40398e99763eW3School 在线教程5db79b134e9f6b82c0b36e0489ee08ed
浏览器用特殊效果显示短语“W3School 在线教程”(通常是带下划线的蓝色文本),这样用户就会知道它是一个可以链接到其他文档的超链接。就像这样:
W3School 在线教程
用户还可以利用浏览器中的选项来自己指定文本颜色、设置链接前和链接后链接文本的颜色。
提示:可以使用 CSS 伪类向文本超链接添加复杂而多样的样式。
更复杂的锚还可以包含图像。下面这个 LOGO 是一个图像链接,点击该图像,可以返回 W3school 的首页:
eaadad625ac430c8516a40398e99763e 67ebfe71f332c3cafc9d09a580f051ab 5db79b134e9f6b82c0b36e0489ee08ed
上面的代码会为 W3School 的 LOGO 添加一个返回首页的超链接:
大多数图形浏览器都会在作为锚的一部分的图像周围放置特殊的边框。通过在 a1f02c36ba31691bcfe87b2722de723b 标签中把图像的 border 属性设置为 0 可以删除超链接的边框。也可以使用 CSS 的边框属性来全局性地改变元素的边框样式。
1809850c78452929b57f9d501736ce99
值 | 描述 |
---|---|
URL | 超链接的 URL。可能的值:
|
Create a hyperlink
This example demonstrates how to create a link in an HTML document.
Using images as links
This example demonstrates how to use images as links.
HTML 3499910bf9dac5ae3c52d5ede7383485 tag
Question mark in php code The functions of are roughly divided into two categories. One is the pair of tags "97b736f66caff527e91ae3cb399205c1" used in PHP tags, and the other is the "?" operator used in the ternary operator. , like this: $a == 1?true:false.
The question mark used in the tag only acts as a delimiter, that is, to identify the beginning and end of the PHP code, and has no substantial program meaning.
The question mark in the ternary operator has a specific program meaning. Its expression method is probably: Condition 1? Condition 2: Condition 3, when condition 1 is true , the function of the question mark is to select condition 2 as the branch to continue execution of the program. That is to say, once the condition is established, condition two will be executed, otherwise condition three will be executed.
Related recommendations:
PHP Study Notes Post Upload Notes
The above is the detailed content of Some basic tags for PHP learning. For more information, please follow other related articles on the PHP Chinese website!