PHP 语法详解
<div style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP 脚本在服务器上执行,<span style="color: black;">而后</span>向浏览器发送回纯 HTML 结果。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">基本</span> PHP 语法</strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP 脚本可<span style="color: black;">安置</span>于文档中的任何位置。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP 脚本以 <?php 开头,以 ?> 结尾:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php// 此处是 PHP 代码?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP 文件的默认文件扩展名是 ".php"。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP 文件<span style="color: black;">一般</span><span style="color: black;">包括</span> HTML 标签以及一些 PHP 脚本代码。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/9aa000382276cdbc5d4~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728272981&x-signature=dvZljzdShFGs1%2FhttNqBVgcUutU%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面的例子是一个简单的 PHP 文件,其中<span style="color: black;">包括</span>了<span style="color: black;">运用</span>内建 PHP 函数 "echo" 在网页上输出文本 "Hello World!" 的一段 PHP 脚本:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">实例</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><!DOCTYPE html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><h1>我的<span style="color: black;">第1</span>张 PHP 页面</h1></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "Hello World!";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">注释:PHP 语句以分号结尾(;)。PHP 代码块的关闭标签<span style="color: black;">亦</span>会自动<span style="color: black;">显示</span>分号(<span style="color: black;">因此呢</span>在 PHP 代码块的最后一行不必<span style="color: black;">运用</span>分号)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">PHP 中的注释</strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/9aa000382675c1d478e~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728272981&x-signature=ooay3n4%2BgHbmohBtvhlRNVPyHaI%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP 代码中的注释不会被<span style="color: black;">做为</span>程序来读取和执行。它<span style="color: black;">独一</span>的<span style="color: black;">功效</span>是供代码编辑者阅读。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">注释用于:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">使其他人理解您正在做的工作 - 注释<span style="color: black;">能够</span>让其他程序员<span style="color: black;">认识</span>您在<span style="color: black;">每一个</span><span style="color: black;">过程</span>进行的工作(<span style="color: black;">倘若</span>您供职于团队)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">提醒自己做过什么 - 大<span style="color: black;">都数</span>程序员都曾经历过一两年后对项目进行返工,<span style="color: black;">而后</span>不得不重新<span style="color: black;">思虑</span><span style="color: black;">她们</span>做过的事情。注释<span style="color: black;">能够</span>记录您在写代码时的思路。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP 支持三种注释:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">实例</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><!DOCTYPE html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// 这是单行注释</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"># 这<span style="color: black;">亦</span>是单行注释</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">/*</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这是多行注释块</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">它横跨了</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">多行</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">*/</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">PHP <span style="color: black;">体积</span>写<span style="color: black;">敏锐</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在 PHP 中,所有用户定义的函数、类和关键词(例如 if、else、echo 等等)都对<span style="color: black;">体积</span>写不<span style="color: black;">敏锐</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在下面的例子中,所有这三天 echo 语句都是合法的(等价):</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">实例</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><!DOCTYPE html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ECHO "Hello World!<br>";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "Hello World!<br>";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">EcHo "Hello World!<br>";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">不外</span>在 PHP 中,所有变量都对<span style="color: black;">体积</span>写<span style="color: black;">敏锐</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在下面的例子中,<span style="color: black;">仅有</span><span style="color: black;">第1</span>条语句会<span style="color: black;">表示</span> $color 变量的值(这是<span style="color: black;">由于</span> $color、$COLOR 以及 $coLOR 被视作三个<span style="color: black;">区别</span>的变量):</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">实例</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><!DOCTYPE html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$color="red";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "My car is " . $color . "<br>";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "My house is " . $COLOR . "<br>";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "My boat is " . $coLOR . "<br>";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/9aa000382b3892197a2~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728272981&x-signature=mld8%2FmKhq0bud%2BIn1KbJWvtqV3A%3D" style="width: 50%; margin-bottom: 20px;"></p>
</div>
楼主的文章深得我心,表示由衷的感谢! 太棒了、厉害、为你打call、点赞、非常精彩等。 一看到楼主的气势,我就觉得楼主同在社区里灌水。
页:
[1]