散分分祈祷我早点学会php。
pigo 2005-03-24 10:15:47 俺正指望php能够混碗稀饭呢,大家别砸我呀。
Php语法和jsp语法对照
功能 Jsp Php
设置http头信息 request.setHeader("X-PowerBy","lizongbo"); header("X-PowerBy","lizongbo");
获取页面参数 String username=request.getParameter("username"); $username
或者
$_REQUEST["username"];
$_GET["username"]
$_POST["username"]
(根据提交表单的method来选择GET和POST)
(所有網頁中使用post和get傳遞的變數,
接收時不可只用「$」,而是必須使用「$_post[]」或「$_get」,
因為新的版本已經不支援「$」了)
页面输出 out.print("a String"); echo "a String";
(或者print "a String";)
获取页面参数数组 String aaa[]=request.getParameterValues("myarray") 先在页面定义参数命名为:
myarray[],然后用print_r($_REQUEST[myarray]);
设置和获取cookie response.addCookie(new Cookie("test","测试Cookie"));
request.getCookies();
setcookie("test", "测试Cookie" .time() , time()+3600);
echo $_COOKIE['testc'];
获取表单提交方式 request.getMethod() $_SERVER['REQUEST_METHOD'];
html字符转义 需要自己写 echo htmlspecialchars("<h1>测试转义</h1>");
SQL转义过滤单引号 自己写 addslashes($lastname)
Session的使用和释放 request.getSession();
session.setAttribute("aaa","bbb");
session.invalidate();
session_start();
session_register("scounter");
//增加计数器
$scounter++;
session_destroy();
获取当前页面的连接 request.getServletPath()
(http://localhost:8080/webapp/test.jsp对应的是/test.jsp,注意前面有斜线) <?echo $PHP_SELF;?>
(http://localhost/phpdemo/zphp.php对应的是/phpdemo/zphp.php)
$_SERVER['REQUEST_URI'] ." 或者". $_SERVER['PHP_SELF']
引用文件 jsp:include include('include.php');
require('include.php');
include_once("inc.php");
require_once("hhh.php");