YII Blog
Yeah Cheung 's Yeah Cheung
yeah

如需合作,请发邮件! (realloveyou@foxmail.com)
热门文章
搜索
计数器
65571
最新留言
链接
最新评论
谈谈PHP的输入输出流
yeah
posted @ Jan 31, 2010 11:57:28 PM
in 教程
, 9180 阅读
手册上说:
PHP 3.0.13 及以上版本,自 PHP 4.3.0 起支持 php://output 和 php://input,自 PHP 5.0.0 起支持 php://filter。
php://stdin
php://stdout
php://stderr
php://output
php://input
php://filter
php://stdin,php://stdout 和 php://stderr 允许访问 PHP 进程相应的输入或者输出流。
php://output 允许向输出缓冲机制写入数据,和 print() 与 echo() 的方式相同。
php://input 允许读取 POST 的原始数据。和 $HTTP_RAW_POST_DATA 比起来,它给内存带来的压力较小,并且不需要任何特殊的 php.ini 设置。php://input 不能用于 enctype="multipart/form-data"。
php://stdin 和 php://input 是只读的,同时 php://stdout,php://stderr 和 php://output 是只写的。
php://filter 是一种设计用来允许过滤器程序在打开时成为流的封装协议。这对于单独具有完整功能的文件函数例如 readfile(),file() 和 file_get_contents() 很有用,否则就没有机会在读取内容之前将过滤器应用于流之上。
也就是说post的原始数据是保存在一个叫php://input的文件。你可以通过简单的文件操作读取里面的数据来控制。
示例:
html部分:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="r.php">
<label>名字
<input type="text" name="name" id="name" />
</label>
<label><br />
密码
<input type="text" name="password" id="password" />
<br />
<input type="submit" name="submit" id="submit" value="提交" />
</label>
<label>
<input type="reset" name="reset" id="reset" value="重置" />
</label>
</form>
</body>
</html>
PHP部分:
if(strtolower($_SERVER['REQUEST_METHOD']) == "post"){
echo file_get_contents("php://input");
}
你试试就知道效果了
Tags - php://output,php://input,
Apr 26, 2025 04:11:43 AM
I love how webbing straps combine functionality with simplicity. No need for bulky ropes or complicated knots. Whether I’m strapping things to my roof rack or bundling equipment, they get the job done. A small tool with big potential—everyone should have a few in their toolbox. .