我試圖做一個腳本。重要的是它總是寫在一個文本文檔中,所以我想要做的是計算它在該文檔中寫入了多少次,有些像計算來自DB的行。計算字符串在文件中重複的次數?
這是可能的嗎?
$myFile = "log.txt";
$OS = "It is running: ";
$ID = "System ID: ";
$Skip = "<br />";
$link = '<a href="';
$link2 = '/status.txt"> Click here to view if it is online</a>';
$fh = fopen($myFile, 'a') or die("can't open file");
$menu_text = $_POST['field1'];
$menu_text2 = $_POST['field2'];
if (empty($menu_text2)) {
echo "No Data Has Been Posted";
fclose($fh);
}
else {
$stringData = $OS . $menu_text . $Skip . $ID . $menu_text2 . $link . $menu_text2 . $link2 . $Skip;
fwrite($fh, $stringData);
fclose($fh);
print_r($menu_text2);
mkdir($menu_text2, 0777);
}