PHP逐行读取文件然后POST到其他页面 php 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 file.txtguuk 武装部guwv 一部分guww 残疾人guxa 开门红guyk 下意识guyw 下半夜gvav 一刀切a.php$file = file_get_contents('file.txt');$content = explode("\n", $file);$url = 'http://localhost/result.php'; // 这里需用http$result = array();echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';foreach($content as $row){ $t = postdata($url, $row); $result[] = array('row'=>$row, 'posttime'=>$t); // 提示 if($t){ echo 'post data success<br>'; }else{ echo 'post data error'; }}print_r($result);function postdata($url, $data){ $pdata = array( 'text' => $data ); $opts = array( 'http' => array( 'method' => 'POST', 'header' => 'content-type:application/x-www-form-urlencoded', 'content' => http_build_query($pdata) ) ); $context = stream_context_create($opts); $result = file_get_contents($url, false, $context); return $result;}result.php$row = isset($_POST['text'])? $_POST['text'] : '';if($row){ echo date('Y-m-d H:i:s');}else{ echo 'error';} 运行时间:Array( [0] => Array ( [row] => guuk 武装部 [posttime] => 2014-06-12 17:27:08 ) [1] => Array ( [row] => guwv 一部分 [posttime] => 2014-06-12 17:27:08 ) [2] => Array ( [row] => guww 残疾人 [posttime] => 2014-06-12 17:27:08 ) [3] => Array ( [row] => guxa 开门红 [posttime] => 2014-06-12 17:27:08 ) [4] => Array ( [row] => guyk 下意识 [posttime] => 2014-06-12 17:27:08 ) [5] => Array ( [row] => guyw 下半夜 [posttime] => 2014-06-12 17:27:08 ) [6] => Array ( [row] => gvav 一刀切 [posttime] => 2014-06-12 17:27:08 )) 防止死锁的方法 php导入excel单元格中的批注怎么导入? Smarty 数组下标的问题 PHP环境搭建问题 超级简单 高手帮忙啊!!! 求一段js正则字符串匹配代码 问个语法问题 microtime: 取得目前时间的 UNIX 时间戳记的百万分之一秒值 是什么意思 请教一个函数 我把字段id设置成auto_increment,在我插入数据的时候,这个怎么写呢? 紧急求教:如何在调用自身的页面里面保持变量的值。 删除第一张表的数据时,修改第二张表的相关字段的数值 安装iwebmall没有安装成功,提示创建表 imall_admin_group失败!
guwv 一部分
guww 残疾人
guxa 开门红
guyk 下意识
guyw 下半夜
gvav 一刀切
a.php$file = file_get_contents('file.txt');
$content = explode("\n", $file);
$url = 'http://localhost/result.php'; // 这里需用http$result = array();echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';foreach($content as $row){
$t = postdata($url, $row);
$result[] = array('row'=>$row, 'posttime'=>$t);
// 提示
if($t){
echo 'post data success<br>';
}else{
echo 'post data error';
}
}print_r($result);function postdata($url, $data){ $pdata = array(
'text' => $data
); $opts = array(
'http' => array(
'method' => 'POST',
'header' => 'content-type:application/x-www-form-urlencoded',
'content' => http_build_query($pdata)
)
); $context = stream_context_create($opts); $result = file_get_contents($url, false, $context); return $result;
}
result.php$row = isset($_POST['text'])? $_POST['text'] : '';if($row){
echo date('Y-m-d H:i:s');
}else{
echo 'error';
}
Array
(
[0] => Array
(
[row] => guuk 武装部
[posttime] => 2014-06-12 17:27:08
) [1] => Array
(
[row] => guwv 一部分
[posttime] => 2014-06-12 17:27:08
) [2] => Array
(
[row] => guww 残疾人
[posttime] => 2014-06-12 17:27:08
) [3] => Array
(
[row] => guxa 开门红
[posttime] => 2014-06-12 17:27:08
) [4] => Array
(
[row] => guyk 下意识
[posttime] => 2014-06-12 17:27:08
) [5] => Array
(
[row] => guyw 下半夜
[posttime] => 2014-06-12 17:27:08
) [6] => Array
(
[row] => gvav 一刀切
[posttime] => 2014-06-12 17:27:08
))