Table of Contents
How to create a cookie?
Syntax
Example 2
How to retrieve the value of Cookie?
如何删除 Cookie?
如果浏览器不支持 Cookie 该怎么办?
实例
定义和用法
提示和注释
制作文本链接
制作图像链接
语法
属性值
5. What does the question mark in php mean?" >5. What does the question mark in php mean?
Home Backend Development PHP Tutorial Some basic tags for PHP learning

Some basic tags for PHP learning

May 03, 2018 am 11:03 AM
php Basic Label

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 tag.

Syntax

1

setcookie(name, value, expire, path, domain);

Copy after login

Example 1

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:

1

2

<?php

setcookie("user", "runoob", time()+3600);?><html>.....

Copy after login

Note: The cookie value is automatically URL-encoded when sending the cookie and automatically decoded when retrieved. (To prevent URL encoding, use setrawcookie() instead.)

Example 2

You can also set the cookie expiration time in another way. This may be simpler than using seconds.

1

2

<?php

$expire=time()+60*60*24*30;setcookie("user", "runoob", $expire);?><html>.....

Copy after login

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:

1

<?php// 输出 cookie 值echo $_COOKIE["user"];// 查看所有 cookieprint_r($_COOKIE);?>

Copy after login

In the following example, we use isset() function to confirm whether the cookie has been set:

1

<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>

Copy after login



当删除 cookie 时,您应当使过期日期变更为过去的时间点。

删除的实例:

1

<?php// 设置 cookie 过期时间为过去 1 小时setcookie("user", "", time()-3600);?>

Copy after login



如果您的应用程序需要与不支持 cookie 的浏览器打交道,那么您不得不使用其他的办法在您的应用程序中的页面之间传递信息。一种方式是通过表单传递数据(有关表单和用户输入的内容,在本教程的前面章节中我们已经介绍过了)。

下面的表单在用户单点击 "Submit" 按钮时,向 "welcome.php" 提交了用户输入:

1

<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>

Copy after login

取回 "welcome.php" 文件中的值,如下所示:

1

<html><head><meta charset="utf-8"><title>菜鸟教程(runoob.com)</title></head><body>欢迎 <?php echo $_POST["name"]; ?>.<br>你 <?php echo $_POST["age"]; ?> 岁了。</body></html>

Copy after login

4. HTML 标签的 href 属性

HTML 标签

实例


href 属性规定链接的目标:

1

<a><a href="http://www.w3school.com.cn">W3School</a></a>

亲自试一试

定义和用法


标签的 href 属性用于指定超链接目标的 URL。

href 属性的值可以是任何有效文档的相对或绝对 URL,包括片段标识符和 JavaScript 代码段。如果用户选择了 标签中的内容,那么浏览器会尝试检索并显示 href 属性指定的 URL 所表示的文档,或者执行 JavaScript 表达式、方法和函数的列表。

提示和注释

注意: 标签中必须提供 href 属性或 name 属性。

制作文本链接

一个引用其他文档的简单 标签可以是下列形式:

1

<a><a href="http://www.w3school.com.cn/index.html">W3School 在线教程</a></a>

浏览器用特殊效果显示短语“W3School 在线教程”(通常是带下划线的蓝色文本),这样用户就会知道它是一个可以链接到其他文档的超链接。就像这样:

W3School 在线教程

用户还可以利用浏览器中的选项来自己指定文本颜色、设置链接前和链接后链接文本的颜色。

提示:可以使用 CSS 伪类向文本超链接添加复杂而多样的样式。

制作图像链接


更复杂的锚还可以包含图像。下面这个 LOGO 是一个图像链接,点击该图像,可以返回 W3school 的首页:

1

2

3

<a><a href="http://www.w3school.com.cn/index.html">

<img src="/i/w3school_logo_white.gif" />

</a></a>

上面的代码会为 W3School 的 LOGO 添加一个返回首页的超链接:

W3School 在线教程

大多数图形浏览器都会在作为锚的一部分的图像周围放置特殊的边框。通过在 标签中把图像的 border 属性设置为 0 可以删除超链接的边框。也可以使用 CSS 的边框属性来全局性地改变元素的边框样式。

语法

1

<a><a href="value"></a>

属性值

描述
URL 超链接的 URL。可能的值:
  • 绝对 URL - 指向另一个站点(比如 href="http://www.example.com/index.htm")

  • 相对 URL - 指向站点内的某个文件(href="index.htm")

  • 锚 URL - 指向页面中的锚(href="#top")


TIY Example

  • 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 tag

5. What does the question mark in php mean?

Question mark in php code The functions of are roughly divided into two categories. One is the pair of tags "" used in PHP tags, and the other is the "?" operator used in the ternary operator. , like this: $a == 1?true:false.

  1. 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.

  2. 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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles