你好,如果是原生的PHP的話,您可以使用echo搭配html標(biāo)簽進(jìn)行輸出數(shù)據(jù)的
創(chuàng)新互聯(lián)于2013年創(chuàng)立,先為南州晴隆等服務(wù)建站,南州晴隆等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為南州晴隆企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
//使用數(shù)組的方法存入,示例如
//index.php
!DOCTYPE?html
html
head
meta?http-equiv="X-UA-Compatible"?content="IE=Edge"?/
meta?http-equiv="content-type"?content="text/html;charset=utf-8"?/
titlephp/title
body
form?method="POST"?action="01.php"
?php
for($i=0;$i10;$i++)
{
echo?"第".$i."個(gè)人姓名:";
??
input?type?="text"?name="name[]"??br/
?php
}
?
input?type?="submit"?name="btn"?value='提交'?br/
/form
/body
/html
//01.php
?php
if($_POST){
$name=$_POST['name'];
print_r($name);
}?
/**
Array
(
[0]?=?chinawinxp1
[1]?=?chinawinxp2
[2]?=?chinawinxp3
[3]?=?chinawinxp4
[4]?=?chinawinxp5
[5]?=?chinawinxp6
[6]?=?chinawinxp7
[7]?=?chinawinxp8
[8]?=?chinawinxp9
[9]?=?chinawinxp10
)**/
?
一、用file_get_contents以get方式獲取內(nèi)容,需要輸入內(nèi)容為:
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函數(shù),以post方式獲取url,需要輸入內(nèi)容為
1、?php
2、$url='';
3、$data=array('foo'='bar');
4、$data=http_build_query($data);
5、$opts=array(
6、'http'=array(
7、?'method'='POST',
8、?'header'="Content-type:application/x-www-form-urlencoded\r\n".
9、??????????"Content-Length:".strlen($data)."\r\n",
10、?'content'=$data
11、)
12、);
13、$ctx=stream_context_create($opts);
14、$html=@file_get_contents($url,'',$ctx);
15、?
三、用fopen打開url,以get方式獲取內(nèi)容,需要輸入內(nèi)容為
1、?php
2、$fp=fopen($url,'r');
3、$header=stream_get_meta_data($fp);//獲取信息
4、while(!feof($fp)){
5、$result.=fgets($fp,1024);
6、}
7、echo"urlheader:{$header}br":
8、echo"urlbody:$result";
9、fclose($fp);
10、?
四、用fopen打開url,以post方式獲取內(nèi)容,需要輸入內(nèi)容為
1、?php
2、$data=array('foo2'='bar2','foo3'='bar3');
3、$data=http_build_query($data);
4、$opts=array(
5、'http'=array(
6、'method'='POST',
7、'header'="Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".
8、"Content-Length:".strlen($data)."\r\n",
9、'content'=$data
10、)
11、);
12、$context=stream_context_create($opts);
13、$html=fopen(';id2=i4','rb',false,$context);
14、$w=fread($html,1024);
15、echo$w;
16、?
五、用fsockopen函數(shù)打開url,以get方式獲取完整的數(shù)據(jù),包括header和body,需要輸入內(nèi)容為
1、?php
2、functionget_url($url,$cookie=false)
3、{
4、$url=parse_url($url);
5、$query=$url[path]."?".$url[query];
6、echo"Query:".$query;
7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
8、if(!$fp){
9、returnfalse;
10、}else{
11、$request="GET$queryHTTP/1.1\r\n";
12、$request.="Host:$url[host]\r\n";
13、$request.="Connection:Close\r\n";
14、if($cookie)$request.="Cookie:??$cookie\n";
15、$request.="\r\n";
16、fwrite($fp,$request);
17、while(!@feof($fp)){
18、$result.=@fgets($fp,1024);
19、}
20、fclose($fp);
21、return$result;
22、}
23、}
24、//獲取url的html部分,去掉header
25、functionGetUrlHTML($url,$cookie=false)
26、{
27、$rowdata=get_url($url,$cookie);
28、if($rowdata)
29、{
30、$body=stristr($rowdata,"\r\n\r\n");
31、$body=substr($body,4,strlen($body));
32、return$body;
33、}
34、?returnfalse;
35、}
36、?
參考資料:
php-file_get_contents
1:首先要使用PHP的超全局變量 $_GET 和 $_POST 用于收集表單數(shù)據(jù)(form-data)
2:然后使用INSERT INTO 語(yǔ)句用于向數(shù)據(jù)庫(kù)表中插入新記錄。
具體示例:
(1)首先創(chuàng)建了一個(gè)名為 "Persons" 的表,有三個(gè)列:"Firstname", "Lastname" 以及 "Age"。
?php
$con?=?mysql_connect("localhost","peter","abc123");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
mysql_select_db("my_db",?$con);
mysql_query("INSERT?INTO?Persons?(FirstName,?LastName,?Age)?
VALUES?('Peter',?'Griffin',?'35')");
mysql_query("INSERT?INTO?Persons?(FirstName,?LastName,?Age)?
VALUES?('Glenn',?'Quagmire',?'33')");
mysql_close($con);
?
(2)其次創(chuàng)建一個(gè) HTML 表單,這個(gè)表單可把新記錄插入 "Persons" 表。
html
body
form?action="insert.php"?method="post"
Firstname:?input?type="text"?name="firstname"?/
Lastname:?input?type="text"?name="lastname"?/
Age:?input?type="text"?name="age"?/
input?type="submit"?/
/form
/body
/html
(3)接著當(dāng)用戶點(diǎn)擊上例中 HTML 表單中的提交按鈕時(shí),表單數(shù)據(jù)被發(fā)送到 "insert.php"。"insert.php" 文件連接數(shù)據(jù)庫(kù),并通過
$_POST 變量從表單取回值。然后,mysql_query() 函數(shù)執(zhí)行 INSERT INTO 語(yǔ)句,一條新的記錄會(huì)添加到數(shù)據(jù)庫(kù)表中。
?php
$con?=?mysql_connect("localhost","peter","abc123");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
mysql_select_db("my_db",?$con);
$sql="INSERT?INTO?Persons?(FirstName,?LastName,?Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if?(!mysql_query($sql,$con))
{
die('Error:?'?.?mysql_error());
}
echo?"1?record?added";
mysql_close($con)
?
先確定你的是php文件 然后:
trtd姓名:/tdtd colspan="2"input name="name" type="text" id="name" value="?php echo $data[1];?"/td/tr
本文名稱:php表單數(shù)據(jù)怎么打 php提交表單數(shù)據(jù)有哪幾種方法
轉(zhuǎn)載注明:http://m.kartarina.com/article4/dodecoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、App開發(fā)、動(dòng)態(tài)網(wǎng)站、企業(yè)建站、網(wǎng)站營(yíng)銷、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)