導航:首頁 > 編程語言 > php寫文本

php寫文本

發布時間:2022-10-01 04:43:40

php寫入文本內容,替換寫入。

把內容"PROXY 114.226.160.169:44932;"寫入文本文件可以使用file_put_contents,例如:
<?php
file_put_contents('a.txt', 'PROXY 114.226.160.169:44932;');
?>

Ⅱ PHP操作txt,寫入文本問題

不多說,手打上代碼。我寫的是php代碼啊,不過php需要運行環境,但是js我不會


<?php
echo"<metacharset=utf-8> ";
$content='';
//生成靜態文件代碼
if(isset($_POST['btn'])){
if(!is_dir('data'))mkdir('data');
$file='data/text11.txt';//路徑,可以自己修改
$content=$_POST['text'];
$fp=fopen($file,w);
fwrite($fp,$content);
fclose($fp);
echo"<scriptlanguage='javascript'> alert('寫入成功') </script> ";
}
//下面是前台顯示
$str="<formmethod='post'action=''> <inputtype='text'name='text'value='$content'> <inputtype='submit'name='btn'value='提交'> </form>";
echo$str;
?>

Ⅲ php怎麼將對象或者數組寫入一個文本文件

第一種:
<?php
$filename = 'test.txt';
$somecontent = "this is test string.";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "不能打開文件 $filename";
exit;
}
// 將$somecontent寫入到我們打開的文件中。
if (fwrite($handle, $somecontent) === FALSE) {
echo "不能寫入到文件 "e;{$filename}"e;";
exit;
}
echo "已把"e;{$somecontent}"e;寫入到文件"e;{$filename}"e;";
fclose($handle); //將指針關閉
} else {
echo "文件{$filename}不可寫.";
}
?>

第二種:
<?php
$filename = "test.txt";
$content = "this is test string.";
$put = file_put_contens($filename,$content);
if(!put)
exit("write failed");
echo "write success";
?>

Ⅳ 編寫php腳本,逐行將行號寫入文本文件「test.txt」

<?php
$file=fopen("test.txt","w");
for($i=1;$i<=20;$i++)
{
fwrite($file,$i." ");
}
fclose($file);
$file=fopen("test.txt","r");
while(!feof($file))
{
echo("<div>".fgets($file)."</div)");
}
fclose($file);
?>

Ⅳ PHP寫入到文本文件亂碼

php處理中文編碼老是有問題,這是編碼的問題,可以將txt文件另存為UTF-8的編碼再處理;

參考如下:

functionfile_utf8($filepath){
$f_contents=file_get_contents($filepath);

$encoding=mb_detect_encoding($f_contents,array('GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII'));

$content_u="";
$handle=fopen($filepath,"r");
if($handle){
while(!feof($handle)){
$buffer=fgets($handle);
if($encoding!=false){
if(mb_detect_encoding($buffer)!='UTF-8'){
$buffer=iconv($encoding,'UTF-8',$buffer);
}
}else{
$buffer=mb_convert_encoding($buffer,'UTF-8','Unicode');
}
$content_u.=$buffer;
}
fclose($handle);
return$info=array('status'=>1,'message'=>$content_u);
}else{
return$info=array('status'=>0,'message'=>'打開文件失敗');
}
}

Ⅵ php 如何寫入文本首行

文本文件屬於順序文件,不是資料庫,不允許向前插入內容,需要插入內容的辦法是把整個文件全部重寫,先寫新內容,再寫舊內容,下面的代碼把$line添加到$fname的前面:

<?php
$line='abc';
$fname='a.html';
file_put_contents($fname,"$line\n".file_get_contents($fname));
?>

注意:以上代碼在PHP5下測試通過,不支持PHP3、PHP4。

Ⅶ php 寫入文本如何換行

用chr(10)寫入到文本文件可以添加換行符
另外,最好用二進制('b')模式打開文件!
你的採納是我前進的動力,
記得好評和採納,互相幫助,
如果你認可我的回答,敬請及時採納.
手機提問的朋友在客戶端右上角評價點【滿意】即可.
如果你認可我的回答,請及時點擊【採納為滿意回答】按鈕!

Ⅷ 請問php中如何自動創建文件並寫入文本呢

<?php
$Res='/a/b';
!is_dir($Res)?mkdir($Res):null;//如果文件夾不存在則創建文件夾
$FileName='c.php';
echofile_put_contents($FileName,'d')?'文件創建成功':'文件創建失敗';

Ⅸ php讀寫文本內容問題

用正則 怎麼實現 我不太清楚 不好意思!

Ⅹ PHP怎麼寫入TXT文檔

php 寫入txt:
PHP
function writelog($str)
{

$open=fopen("log.txt","a" );
fwrite($open,$str);
fclose($open);
}

'a' 寫入方式打開,將文件指針指向文件末尾。如果文件不存在則嘗試創建之。
'a+' 讀寫方式打開,將文件指針指向文件末尾。如果文件不存在則嘗試創建之。

php txt 換行
"\r\n"
不可用單引號.

閱讀全文

與php寫文本相關的資料

熱點內容
歐拉app怎麼下訂單 瀏覽:422
肉文有聲小說 瀏覽:955
求個看片的網址 瀏覽:547
pythonsin函數圖像 瀏覽:329
身體不好當程序員 瀏覽:274
mount命令作用 瀏覽:220
畫江湖之不良人黑白無常雙修刪減 瀏覽:754
朵唯手機如何加密 瀏覽:504
安卓雙清指的什麼 瀏覽:177
phpredis所有keys 瀏覽:988
朋友賣房要解壓嗎 瀏覽:108
sar命令安裝 瀏覽:169
安卓怎麼看我自己去過哪裡 瀏覽:283
演算法分析里log沒有底數嗎 瀏覽:222
伺服器卡頓怎麼連接 瀏覽:957
手機拍照文件夾自動生成 瀏覽:788
瀏覽器如何運行在伺服器端 瀏覽:790
collinux 瀏覽:449
日本歐美韓國推理片電影大分享 瀏覽:615
怎麼下載香港app游戲 瀏覽:217