注册 登录
编程论坛 PHP技术论坛

[求助]关于定义变量问题

xxygdufs 发布于 2006-07-02 13:22, 843 次点击

<html>
<head>
<title>php预定义常量.</title>
</head>
<body>
<script language="php">
define (STR,"so handsome");
echo STR;
echo(__line__);
echo "<p>";
echo(__file__);
echo "<p>";
echo PHP_VERSION;
echo "<p>";
echo PHP_OS;
echo "<p>";
//define (str,"so handsome");
//echo str;
</script>
</body>
</html>
上面七八行错在哪

4 回复
#2
lj_8606032006-07-02 19:59
以下是引用xxygdufs在2006-7-2 13:22:02的发言:

<html>
<head>
<title>php预定义常量.</title>
</head>
<body>
<script language="php">
define (STR,"so handsome"); //==》STR 改成 "STR"(即加上双引号),这样就OK了
echo STR;
echo(__line__);
echo "<p>";
echo(__file__);
echo "<p>";
echo PHP_VERSION;
echo "<p>";
echo PHP_OS;
echo "<p>";
//define (str,"so handsome");
//echo str;
</script>
</body>
</html>
上面七八行错在哪

#3
lj_8606032006-07-02 20:02
楼主看一下define()的语法就可以了。不要看一些比较关于PHP3或者更老的版本的书籍,因为PHP4中改变了PHP3中的一些内容,所以你照着书敲代码也许在编译器上是通不过的。可以多到PHP的一些学习网站上下载一些比较新的内容。
#4
lj_8606032006-07-02 20:05
还有,在ZEND上类如<html>,<body>这些都可以省略,不知道你看的书是关于PHP什么版本的,你用了
<script language="php">,一般在ZEND上直接敲 :
<?php

// code

?>
这样就可以了。
#5
lj_8606032006-07-02 20:18

贴一个关于define()原型和用法给LZ吧,是英文哦
----------------------------------------
Description
bool define ( string name, mixed value [, bool case_insensitive])

Defines a named constant. See the section on constants for more details.

The name of the constant is given by name; the value is given by value.

The optional third parameter case_insensitive is also available. If the value TRUE is given, then the constant will be defined case-insensitive. The default behaviour is case-sensitive; i.e. CONSTANT and Constant represent different values.

例子 1. Defining Constants

<?php
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a notice.

define("GREETING", "Hello you.", true);
echo GREETING; // outputs "Hello you."
echo Greeting; // outputs "Hello you."

?>
如果成功则返回 TRUE,失败则返回 FALSE。

1