第二章 PHP基本语法
初识php脚本程序
输出hello world
(1)php可以单独使用
<?php echo"hello world";?>
(2)php代码可以嵌入到html中且可以嵌入到任何地方,可以嵌入多个
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<?php echo "hello world";?>
</body>
</html>
(3)文件末尾的?>可以省略不要
<?php echo"hello world";
(4)文末有结束标志可以不加分号
<?php echo"hello world"?>
注释
(1)单行注释
<?php
//echo"hello world";
//echo"hello world";
//echo"hello world";
?>
(2)多行注释
<?php
/*echo"hello world";
echo"hello world";
echo"hello world";*/
?>
输出语句
echo
echo可以将紧跟其后一个或多个字符串、表达式、变量和常量的值输出到页面中,多个数据之间用","分割
echo 'hello world';
echo 'result=',4+3*3;
print与echo用法相同,唯一区别是print一次只能输出一个值
print 'best';
print_r()
print_r()是PHP的内置函数,它可以输出任意类型的数据,如字符串、数组等。

本文介绍了PHP的基本语法,包括初识PHP脚本程序,输出语句如echo和print,PHP标识符的规则,变量的声明、赋值和销毁,常量的定义,以及各种数据类型和运算符的使用。
最低0.47元/天 解锁文章
1620

被折叠的 条评论
为什么被折叠?



