Heim >Backend-Entwicklung >PHP-Tutorial >PHP 基础教程1 php语言基础 php0基础 php基础实
什么是 PHP 文件?
PHP 文件能够包含文本、HTML、CSS 以及 PHP 代码
PHP 代码在服务器上执行,而结果以纯文本返回浏览器
PHP 文件的后缀是 “.php”
PHP 能够做什么?
PHP 能够生成动态页面内容
PHP 能够创建、打开、读取、写入、删除以及关闭服务器上的文件
PHP 能够接收表单数据
PHP 能够发送并取回 cookies
PHP 能够添加、删除、修改数据库中的数据
PHP 能够限制用户访问网站中的某些页面
PHP 能够对数据进行加密
通过 PHP,您可以不受限于只输出 HTML。您还能够输出图像、PDF 文件、甚至 Flash 影片。您也可以输出任何文本,比如 XHTML 和 XML。
PHP 支持三种注释:
<code><span><span>html</span>></span><span>body</span>><span><span><?php </span><span>// 这是单行注释</span><span># 这也是单行注释</span><span>/* 这是多行注释块 它横跨了 多行 */</span><span>?></span></span><span><span>body</span>></span><span><span>html</span>></span></span></code>
PHP 大小写敏感
在 PHP 中,所有用户定义的函数、类和关键词(例如 if、else、echo 等等)都对大小写不敏感。
在下面的例子中,所有这三个 echo 语句都是合法的(等价):
实例
<code><span><span>html</span>></span><span>body</span>><span><span><?php </span><span>ECHO</span><span>"Hello World!<br>"</span>; <span>echo</span><span>"Hello World!<br>"</span>; <span>EcHo</span><span>"Hello World!<br>"</span>; <span>?></span></span><span><span>body</span>></span><span><span>html</span>></span></span></code>
Hello World!
Hello World!
Hello World!
不过在 PHP 中,所有变量都对大小写敏感。
在下面的例子中,只有第一条语句会显示
实例
<code><span><span><span>html</span>></span><span>body</span>></span><span><span><?php </span><span>$color</span>=<span>"red"</span>; <span>echo</span><span>"My car is "</span> . <span>$color</span> . <span>"<br>"</span>; <span>echo</span><span>"My house is "</span> . <span>$COLOR</span> . <span>"<br>"</span>; <span>echo</span><span>"My boat is "</span> . <span>$coLOR</span> . <span>"<br>"</span>; <span>?></span></span><span><span>body</span>></span><span><span>html</span>></span></span></code>
My car is red
My house is
My boat is
PHP 5 echo 和 print 语句
PHP echo 和 print 语句
echo 和 print 之间的差异:
echo - 能够输出一个以上的字符串
print - 只能输出一个字符串,并始终返回 1
提示:echo 比 print 稍快,因为它不返回任何值。
PHP echo 语句
echo 是一个语言结构,有无括号均可使用:echo 或 echo()。
<code><span><span>html</span>></span><span>body</span>><span><span><?php </span><span>echo</span><span>"<h2>PHP 很有趣!</h2>"</span>; <span>echo</span><span>"Hello world!<br>"</span>; <span>echo</span><span>"我计划学习 PHP!<br>"</span>; <span>echo</span><span>"这段话"</span>, <span>"由"</span>, <span>"多个"</span>, <span>"字符串"</span>, <span>"串接而成。"</span>; <span>$txt1</span>=<span>"Learn PHP"</span>; <span>$txt2</span>=<span>"W3School.com.cn"</span>; <span>$cars</span>=<span>array</span>(<span>"Volvo"</span>,<span>"BMW"</span>,<span>"SAAB"</span>); <span>echo</span><span>$txt1</span>; <span>echo</span><span>"<br>"</span>; <span>echo</span><span>"Study PHP at $txt2"</span>; <span>echo</span><span>"<br>"</span>; <span>echo</span><span>"My car is a {$cars[0]}"</span>; <span>?></span></span><span><span>body</span>></span><span><span>html</span>></span></span></code>
Hello world!
我计划学习 PHP!
这段话由多个字符串串接而成。
Learn PHP
Study PHP at W3School.com.cn
My car is a Volvo
PHP print 语句
print 也是语言结构,有无括号均可使用:print 或 print()。
<code><span><span><span>html</span>></span><span>body</span>></span><span><span><?php </span><span>print</span><span>"<h2>PHP is fun!</h2>"</span>; <span>print</span><span>"Hello world!<br>"</span>; <span>print</span><span>"I'm about to learn PHP!"</span>; <span>$txt1</span>=<span>"Learn PHP"</span>; <span>$txt2</span>=<span>"W3School.com.cn"</span>; <span>$cars</span>=<span>array</span>(<span>"Volvo"</span>,<span>"BMW"</span>,<span>"SAAB"</span>); <span>print</span><span>$txt1</span>; <span>print</span><span>"<br>"</span>; <span>print</span><span>"Study PHP at $txt2"</span>; <span>print</span><span>"<br>"</span>; <span>print</span><span>"My car is a {$cars[0]}"</span><span>?></span></span><span><span>body</span>></span><span><span>html</span>></span></span></code>
PHP is fun!
Hello world!
I’m about to learn PHP!
Learn PHP
Study PHP at W3School.com.cn
My car is a Volvo
以上就介绍了PHP 基础教程1,包括了php,基础方面的内容,希望对PHP教程有兴趣的朋友有所帮助。