此代碼允許創建新的.txt文件,如果該文件尚不存在,則會創建該文件。搜索文件並將搜索詞遷移到新文件
<?php
$file = 'people.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
file_put_contents($file, $current);
?>
而這裏的代碼標識了每一行字符串到一個標記。
<?php
$string = "This is\tan example\nstring";
/* Use tab and newline as tokenizing characters as well */
$tok = strtok($string, " \n\t");
while ($tok !== false) {
echo "Word=$tok<br />";
$tok = strtok(" \n\t");
}
?>
的people.txt看起來像這樣
John Smith
John Meyer
John Chase
John Smith //i want to transfer this set of string into a new file
我失去的是什麼?
你的問題是什麼? – 2010-11-12 14:04:21
我想通過首先識別第一個和最後一個字符串,將一組字符串轉換爲不同的文件。 – woninana 2010-11-12 14:10:07