当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > PHP 变量

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 变量


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1540 ::
收藏到网摘: n/a

Variables are used for storing values, such as numbers, strings or function results, so that they can be used many times in a script.
“变量”是用来存储“值”的,如:数字(number)、字符串(string)或者函数结果(function results);它可以在脚本种重复使用。


Variables in PHP
PHP变量

All variables in PHP start with a $ sign symbol. Variables may contain strings, numbers, or arrays.
所有的PHP变量的前面都包含一个“$”符号。变量可以包含字符串、数字、数组。

Below, the PHP script assigns the string "Hello World" to a variable called $txt:
下面的案例中,我们先给“txt”附一个字符串“Hello World”,然后再显示这个“txt”变量:

<html>
<body>
<?php
$txt="Hello World";
echo $txt;
?>
</body>
</html>

To concatenate two or more variables together, use the dot (.) operator:
如果你想把两个变量合二为一,你需要使用(.)操作符,具体如下:

<html>
<body>
<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2 ;
?>
</body>
</html>

The output of the script above will be: "Hello World 1234".
上述例子输出的结果是:"Hello World 1234"


Variable Naming Rules
变量命名规则

  • A variable name must start with a letter or an underscore "_"
    一个变量的开头必须是一个字母或下划线“_”。
  • A variable name can only contain alpha-numeric characters and underscores (a-Z, 0-9, and _ )
    一个变量的名称只能包含字母、数字、下划线“_”(即:a-Z, 0-9 和 _)
  • A variable name should not contain spaces. If a variable name should be more than one word, it should be separated with underscore ($my_string), or with capitalization ($myString)
    变量名称不能含有空格(space)。如果一个变量中需要包含多个单词,那单词之间必须以下划线“_”连接,如:($my_string);或者使用大写字母,如:($myString)

评论 (2) 1 All

登陆 | 还没注册?