初学PHP,关于常量和全局变量的一点小问题
kvew 2006-11-25 02:07:29 版本信息如下
[secoder@localhost php]$ php -vision
PHP 5.0.4 (cli) (built: May 9 2005 11:21:11)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies
--------------------------
<?php
// the usage of constant
function report_error($file, $line, $message) {
echo "An error occured in $file on line $line: $message";
} // declear our own function
report_error(_FILE_,_LINE_, "Something went wrong!<br>");
?>
-----------------------------
打印结果却为
An error occured in _FILE_ on line _LINE_: Something went wrong!
还有一个问题,
--------------------------------
<html>
<head><title>regular expression</title><head>
<body>
<a href="./">return<a>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
Please input the Date:
<input type="text" name="date" value="<? echo $date; ?>" >
<input type="submit" value="Transfor to YYYY-MM-DD">
</form>
<?
if(isset($date)){
if ( ereg("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $date, $regs))
{
echo $regs[0]."Result:".$regs[3]."-".$regs[1]."-".$regs[2];
} else {
echo "Wrong date type!\n";
}
}
?>
</body>
</html>
--------------------------------------
这里 <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> 这样才行,但用$PHP_SELF就不行
另外出错信息
<input type="text" name="date" value="PHP Notice: Undefined variable: date in /home/secoder/study/programs/php/stransfor_DateType.php on line 7
初学,还望各位指教下