我有這個問題,我無法設法完成這個簡單的腳本。基本上,我想從表單中獲取一篇文章,將其分配給一個變量,然後將該變量追加到一個預先存在的example.txt文件中。我對缺乏示例表示歉意,在我和我的分社出去吃晚餐後,我轉到了手機。任何人都可以發佈一個簡單的例子,並讓我從這個基礎上建立起來?在此先感謝php後變量,然後附加到txt
0
A
回答
2
以下應該給你一個基礎開始。
<?php
// Check to see if the form was submitted
if(isset($_POST['action']) && $_POST['action'] == 'add'){
$file = 'example.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= $_POST['test'];
// Write the contents back to the file
file_put_contents($file, $current);
}
?>
<form method="POST">
<!-- This becomes PHP variable $_POST['test'] -->
<input type="text" name="test" />
<input type="hidden" name="action" value="add" />
<input type="submit" value="Add"/>
</form>
查看http://us3.php.net/file_put_contents瞭解更多信息。
+0
這種方式很有魅力,非常感謝你 – user3221563
-1
如果你的HTML表單有這樣一個文本字段 <input type="text" name="firstName" value="Name">
你可以在你的PHP腳本使用 $_POST['firstName'];.
如果要附加在PHP中的文本訪問該值,你可以簡單地做它用「」 例如:$post_string = 'Ex:' . $post_string;
+0
哦!爲什麼倒票.. :( – IBunny
相關問題
- 1. jquery post變量爲php,然後發送到.txt文件?
- 2. 在datagridview列後添加空格將txt附加到txt文件
- 3. 瀏覽到圖像文件,然後附加到PHP郵件
- 4. 將數據從PHP然後HTML然後jQuery然後回到PHP
- 5. PHP變量後
- 6. 傳遞php數組到javascript變量,然後到服務器
- 7. PHP讀取從一個txt文件數量,使然後計算
- 8. 劈裂成線然後到變量
- 9. 附加.TXT到MFMailComposeViewController
- 10. VBS如果變量>變量然後
- 11. 使用.Split(),然後加入這些值以3個PHP變量
- 12. 如何在php中添加函數變量,然後執行
- 13. jQuery變量爲PHP變量,然後在查詢中使用它
- 14. PHP數組賦值然後得到變量值
- 15. PHP獲得價值,然後把它放到一個變量
- 16. 分隔txt文件到數組?然後更新MySQL PHP
- 17. 附加然後刪除元素與jQuery
- 18. 覆蓋文件,然後附加
- 19. PHP MySQL查詢結果到一個變量,然後回聲($變量)
- 20. 如果變量在db然後停止 - 如果變量不 - 然後輸入它
- 21. 將30天添加到sql中的變量,然後在php中回顯
- 22. 如何確認提示值,然後將1加到變量
- 23. x時間後增加PHP變量
- 24. PHP在變量之後/之前添加「」
- 25. 循環到變量然後打印變量
- 26. 追加txt文件 - 然後閱讀txt文件到語料庫與TM封裝
- 27. 插入PHP變量到XML捲曲後
- 28. 阿賈克斯後到PHP空變量
- 29. 當變量被設置然後(等待直到被設置然後執行)
- 30. 得到變量後
當你有機會回到桌面時,給我們一個當前代碼的例子。 – Coderchu
在詢問你是否打算得到答案之前,請先閱讀*如何詢問*網頁。 –