PHP 基础教程1

什么是 PHP 文件?

PHP 文件能够包含文本、HTML、CSS 以及 PHP 代码
PHP 代码在服务器上执行,而结果以纯文本返回浏览器
PHP 文件的后缀是 “.php”


PHP 能够做什么?

PHP 能够生成动态页面内容
PHP 能够创建、打开、读取、写入、删除以及关闭服务器上的文件
PHP 能够接收表单数据
PHP 能够发送并取回 cookies
PHP 能够添加、删除、修改数据库中的数据
PHP 能够限制用户访问网站中的某些页面
PHP 能够对数据进行加密
通过 PHP,您可以不受限于只输出 HTML。您还能够输出图像、PDF 文件、甚至 Flash 影片。您也可以输出任何文本,比如 XHTML 和 XML。


PHP 支持三种注释:

<!DOCTYPE html>
<html>
<body>

<?php
// 这是单行注释

# 这也是单行注释

/*
这是多行注释块
它横跨了
多行
*/
?>

</body>
</html>

PHP 大小写敏感

在 PHP 中,所有用户定义的函数、类和关键词(例如 if、else、echo 等等)都对大小写不敏感。
在下面的例子中,所有这三个 echo 语句都是合法的(等价):
实例

<!DOCTYPE html>
<html>
<body>

<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>

</body>
</html>

Hello World!
Hello World!
Hello World!


不过在 PHP 中,所有变量都对大小写敏感。
在下面的例子中,只有第一条语句会显示 color color、 COLOR coLOR 被视作三个不同的变量):
实例

<!DOCTYPE html>
<html>
<body>

<?php
$color="red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My boat is " . $coLOR . "<br>";
?>

</body>
</html>

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()。

<!DOCTYPE html>
<html>
<body>

<?php
echo "<h2>PHP 很有趣!</h2>";
echo "Hello world!<br>";
echo "我计划学习 PHP!<br>";
echo "这段话", "由", "多个", "字符串", "串接而成。";
$txt1="Learn PHP";
$txt2="W3School.com.cn";
$cars=array("Volvo","BMW","SAAB");
echo $txt1;
echo "<br>";
echo "Study PHP at $txt2";
echo "<br>";
echo "My car is a {$cars[0]}";

?>  

</body>
</html>

Hello world!
我计划学习 PHP!
这段话由多个字符串串接而成。
Learn PHP
Study PHP at W3School.com.cn
My car is a Volvo

PHP print 语句
print 也是语言结构,有无括号均可使用:print 或 print()。


<!DOCTYPE html>
<html>
<body>

<?php
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";

$txt1="Learn PHP";
$txt2="W3School.com.cn";
$cars=array("Volvo","BMW","SAAB");
print $txt1;
print "<br>";
print "Study PHP at $txt2";
print "<br>";
print "My car is a {$cars[0]}"
?>  

</body>
</html>

PHP is fun!

Hello world!
I’m about to learn PHP!
Learn PHP
Study PHP at W3School.com.cn
My car is a Volvo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值