PHP+MySQL
php开发工具 ZendStudio-7.2.0 MySQL Server 5.0,MySql辅助工具Navicat 8 Lite for MySQL 今天(2010-7-6)开始研究下Php PHP语法: ? php ? html body ? php echo " Hello World " ; ? / body / html PHP 中的每个代码行都必须以分号结束。分号是一种分隔
php开发工具 ZendStudio-7.2.0
MySQL Server 5.0,MySql辅助工具Navicat 8 Lite for MySQL
今天(2010-7-6)开始研究下Php
PHP语法:
<p><span></span><span>php<br><br></span><span>?></span></p>
<p><span><span>html</span><span>></span><span><br></span><span><span>body</span><span>></span><span><br><br></span><span></span><span>php<br></span><span>echo</span><span>"</span><span>Hello World</span><span>"</span><span>;<br></span><span>?></span><span><br><br></span><span></span><span>body</span><span>></span><span><br></span><span></span><span>html</span><span>></span></span></span></p>
PHP 中的每个代码行都必须以分号结束。分号是一种分隔符,用于把指令集区分开来。
有两种通过 PHP 来输出文本的基础指令:echo 和 print。在上面的例子中,我们使用了 echo 语句来输出文本 "Hello World"。
PHP 中的变量
变量用于存储值,比如数字、文本字符串或数组。
一旦设置了某个变量,我们就可以在脚本中重复地使用它。
PHP 中的所有变量都是以 $ 符号开始的。
在 PHP 中设置变量的正确方法是:
$var_name = value;
PHP 的入门者往往会忘记在变量的前面的 $ 符号。如果那样做的话,变量将是无效的。
让我们试着创建一个存有字符串的变量,和一个存有数值的变量:
<?php $txt = "Hello World!";$number = 16;?>
PHP 是一门松散类型的语言(Loosely Typed Language)
在 PHP 中,不需要在设置变量之前声明该变量。
在上面的例子中,您看到了,不必向 PHP 声明该变量的数据类型。
根据变量被设置的方式,PHP 会自动地把变量转换为正确的数据类型。
在强类型的编程语言中,您必须在使用前声明变量的类型和名称。
在 PHP 中,变量会在使用时被自动声明。
并置运算符(Concatenation Operator)
<p><span>在 PHP 中,只有一个字符串运算符。<br><br>并置运算符 (</span><span>.</span><span>) 用于把两个字符串值连接起来。<br><br>要把两个变量连接在一起,请使用这个点运算符 (</span><span>.</span><span>) :<br><br></span><span></span><span>php<br></span><span>$txt1</span><span>=</span><span>"</span><span>Hello World</span><span>"</span><span>;<br></span><span>$txt2</span><span>=</span><span>"</span><span>1234</span><span>"</span><span>;<br></span><span>echo</span><span>$txt1</span><span>.</span><span>"</span><span>"</span><span>.</span><span>$txt2</span><span>;<br></span><span>?></span><span><br>以上代码的输出:<br><br>Hello World 1234您可以看到,我们在上面的例子中使用了两次并置运算符。这是由于我们需要插入第三个字符串。<br><br>为了分隔这两个变量,我们在 </span><span>$txt1</span><span> 与 </span><span>$txt2</span><span> 之间插入了一个空格。<br></span></p>
<p><span>strlen</span><span>() 函数用于计算字符串的长度。<br><br>让我们算出字符串 </span><span>"</span><span>Hello world!</span><span>"</span><span> 的长度:<br><br></span><span></span><span>php<br></span><span>echo</span><span>strlen</span><span>(</span><span>"</span><span>Hello world!</span><span>"</span><span>);<br></span><span>?></span><span><br>以上代码的输出:<br><br>12字符串的长度信息常常用在循环或其他函数中,因为那时确定字符串何时结束是很重要的(例如,在循环中,我们需要在字符串中的最后一个字符之后结束循环)。<br></span></p>
使用 strpos() 函数
<p><span>strpos</span><span>() 函数用于在字符串内检索一段字符串或一个字符。<br><br>如果在字符串中找到匹配,该函数会返回第一个匹配的位置。如果未找到匹配,则返回 </span><span>FALSE</span><span>。<br><br>让我们试一下,是不是能在字符串中找到子字符串 </span><span>"</span><span>world</span><span>"</span><span>:<br><br></span><span></span><span>php<br></span><span>echo</span><span>strpos</span><span>(</span><span>"</span><span>Hello world!</span><span>"</span><span>,</span><span>"</span><span>world</span><span>"</span><span>);<br></span><span>?></span><span> <br>以上代码的输出是: <br><br>6正如您看到的,在我们的字符串中,字符串 </span><span>"</span><span>world</span><span>"</span><span> 的位置是 </span><span>6</span><span>。返回 </span><span>6</span><span> 而不是 </span><span>7</span><span>,是由于字符串中的首个位置的 </span><span>0</span><span>,而不是 </span><span>1</span><span>。<br></span></p>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

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

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,

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

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.

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.
