我已經有一個表單上傳文本輸入行到一個.txt文件,並希望顯示文本文件的最後25行與文本輸入窗體(我也想給每行一個隨機左邊距值1-800px之間) - 我該如何實現它?將.txt文件的最後25行發佈到網站上?
2
A
回答
3
我想你會想看看file(),array_slice()和rand()。
也許是這樣的:
$output = "";
$lines = array_slice(file("test.txt"), -25, 25);
foreach ($lines as $line)
{
$output .= '<div style="margin-left: ' . rand(1, 800) . 'px;">' . $line . '</div>';
}
echo $output;
0
那麼你要麼必須在整個文件作爲線的陣列讀,挑過去的25或使用shell命令tail -n 25
。然後在<p>
標籤中隨機輸出margin-left
樣式。
0
- 首先調用file讀取文件的內容在一個陣列
- 然後調用array_slice讀這個數組最後25行。
0
如果你使用的是Unix-y服務器,那麼$lines = array(); $result = exec("tail -25 $filename", $lines)
應該會給你你所需要的。輸出可能涉及foreach($lines as $line) { ... }
和內聯CSS,如echo '<p style="margin-left:' . rand(1, 800) . 'px;">' . $line . '</p>'.
+0
如果你這樣做,確保$ filename是安全的。 – 2011-05-11 22:54:39
相關問題
- 1. 將文檔發佈到Joomla網站
- 2. Android - 如何將txt文件上傳到網站?
- 3. 未能將最後一行添加到.txt文件中 - Android
- 4. 發佈到PHP腳本,然後使用curl將文本/文件數據發佈到外部網站
- 5. 從命令行bat文件發佈ASP.NET網站,最終的.bat文件
- 6. 網站更新後發佈
- 7. 將文本框中的數據發佈到txt文件中
- 8. 發佈網站後的Ajax網址
- 9. 將asp.net網站發佈到單個dll文件中
- 10. 移動.txt文件的第一行到最後一行
- 11. 從後面的代碼將數據發佈到其他網站
- 12. 如何將數據發佈到網站
- 13. 將內容發佈到網站
- 14. 如何將dotnetnuke網站發佈到Azure?
- 15. 將Visual Studio網站發佈到GoDaddy
- 16. 在azure上發佈網站
- 17. C#將文件上傳到網站
- 18. 將文件上傳到Azure網站
- 19. 如何將文件上傳到網站?
- 20. 將文件上傳到網站
- 21. 將文件上傳到網站?
- 22. 將網站代碼導出到txt文件
- 23. 無法找到成功發佈到Azure網站的文件?
- 24. Android將數據發佈到網站上的表單
- 25. 發佈Python代碼的最佳網站?
- 26. 發佈到現場網站
- 27. 網站CSS文件會加載發佈
- 28. 發佈網站獲取空文件夾
- 29. 發佈網站使用csproj文件
- 30. 將網站發佈到Azure後自定義css字體顯示
你能澄清你的問題嗎? – soandos 2011-05-11 22:46:49