编写PHP脚本以在文本文件(标题为a.txt)中搜索单词。文本文件包含50个单词,每个单词占一行。在JavaScript端,客户端在文本字段中键入一个随机单词并提交该单词。PHP脚本使用一个循环搜索这50个单词以找到正确的单词,该循环一直运行到在.txt文件中找到该单词为止。如果找不到该单词,则必须显示一条错误消息,指出该单词不在列表中。
JavaScript部分是正确的,但我在使用PHP时遇到了问题:
$file = fopen("a.txt","r") or die("File does not exist in the current folder
想象一下,我有一个这样的文本文件:
Welcome to the text file!
-------------------------
Description1: value1
Description2: value2
Description containing spaces: value containing spaces
Description3: value3
将这些数据存储到文本文件中很容易,如下所示:
$file = 'data/preciousdata.txt';
// The new data to add to the file
$put
我最终要做的是获取一个如下所示的文本文件,并将它们组织成一些我可以使用的东西,比如一个基于制表符空格的数组。
//示例//
this is no tabbed space
this is a tabbed space
this is 2 tabbed spaces
this is no tabbed space
我想以以下方式结束:(最好使用PHP )
$list= array(no \t("string", "string", "string", one \t ("string", "st
我有一个输出到文本文件的日历脚本。我打开文本文件,将其读入数组,然后输出结果。文本文件包含:
7/9/2013-7/13/2013
Hot Stuff
By Robert More. Yes, folks, it's all platform shoes, leisure suits..
hotstuff.jpg
1,1,0,
*-*
7/16/2013-7/20/2013
Hot Stuff
By Robert More. Yes, folks, it's all platform shoes, leisure suits..
hotstuff.jpg
1,1,0,
*-*
如何在PHP中设置文本文件编码(例如UTF-8)?
让我告诉你我的问题。这是我的密码:
<?php
file_put_contents('test.txt', $data); // data is some non-English text with UTF-8 charset
?>
输出:اÙ!
fwrite()具有类似的输出。
但是当我通过记事本创建test.txt并设置字符集UTF-8时,输出就是我想要的。我想在PHP文件中设置字符集。
下面是我的问题:如何通过PHP设置文本文件编码?