php將數(shù)據(jù)數(shù)據(jù) php數(shù)據(jù)傳輸

php將數(shù)據(jù)寫入文件

使用form表單post數(shù)據(jù)到PHP,然后用file_put_contents($fileName, $data)寫入文件,$fileName是文件名,$data是要寫入的數(shù)據(jù)

創(chuàng)新互聯(lián)公司專注于嵐皋企業(yè)網(wǎng)站建設,響應式網(wǎng)站,電子商務商城網(wǎng)站建設。嵐皋網(wǎng)站建設公司,為嵐皋等地區(qū)提供建站服務。全流程按需求定制設計,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務

新建一個a.php文件,將下面的復制進去訪問一下,填寫后點擊提交,會生成一個a.txt的文件,里面是你填寫的內容

可能會有一個notice的報錯,不必理會

?php

$data = $_POST['text'];

$fileName = 'a.txt';

file_put_contents($fileName, $data);

?

!doctype html

html

head

meta charset="utf-8"

titletest/title

/head

body

form action="./a.php" method="post"

textarea name="text" id="" cols="30" rows="10"/textarea

input type="submit" value="提交"

/form

/body

/html

php怎么把數(shù)據(jù)導入數(shù)據(jù)庫

需要PHP基礎知識和數(shù)據(jù)庫基礎知識。

以SQL為例。使用PHP MySQL 函數(shù)可以編輯數(shù)據(jù)庫。

mysql_connect() 函數(shù)打開MySQL 連接。舉例

?php

$con = mysql_connect("localhost","mysql_user","mysql_pwd");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}// 一些代碼...mysql_close($con);

?

mysql_connect()三個參數(shù)分別是服務器名,連接賬號,連接密碼。

連接之后,可以使用mysql_select_db()設置要處理的數(shù)據(jù)庫,后面則是用數(shù)據(jù)庫語句處理數(shù)據(jù)。SQL語法簡介網(wǎng)頁鏈接

PHP將數(shù)據(jù)寫入txt文件

//記錄返回值

? ? $write_data_a = [

? ? ? ? 'html_url'? =? $getUrl,

? ? ? ? 'ip'? ? = $this-get_real_ip(),

? ? ? ? 'time'? =? date("Y-m-d H:i:s",time()),

? ? ? ? 'res'?? = $response

? ? ];

//轉化為JSON

? ? $write_data_a = json_encode($write_data_a) . '||' . "\n";

? ? $date = date("Y-m-d", time());

//項目路徑目錄,判斷是否存在,不存在則創(chuàng)建

? ? $lujing = "./360_mobile_res_sd";

? ? if(!is_dir($lujing)){

? ? ? ? mkdir(iconv("UTF-8", "GBK", $lujing),0777,true);

? ? }

//文件,判斷是否存在,不存在則創(chuàng)建

? ? $TxtFileName = "./360_mobile_res_sd/" . $date . "_2.txt";

? ? //以讀寫方式打寫指定文件,如果文件不存則創(chuàng)建

? ? if(file_exists($TxtFileName))

? ? {

//存在,追加寫入內容

? ? ? ? file_put_contents($TxtFileName, $write_data_a, FILE_APPEND);

? ? }

? ? else

? ? {

//不存在,創(chuàng)建并寫入

? ? ? ? if( ($TxtRes=fopen ($TxtFileName,"w+")) === FALSE){

? ? ? ? ? ? exit();

? ? ? ? }

? ? ? ? if(!fwrite ($TxtRes,$write_data_a)){ //將信息寫入文件

? ? ? ? ? ? fclose($TxtRes);

? ? ? ? ? ? exit();

? ? ? ? }

? ? ? ? fclose ($TxtRes); //關閉指針

? ? }

網(wǎng)站欄目:php將數(shù)據(jù)數(shù)據(jù) php數(shù)據(jù)傳輸
分享網(wǎng)址:http://www.bm7419.com/article16/ddcspgg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設計、云服務器、域名注冊、電子商務網(wǎng)站營銷、用戶體驗

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站