此代码可以创建一个新的 .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
我在这里想念什么?