Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP替换文件中的特定行_Php_Arrays_File_Lines - Fatal编程技术网

PHP替换文件中的特定行

PHP替换文件中的特定行,php,arrays,file,lines,Php,Arrays,File,Lines,实际上,我在网上找不到任何答案。当涉及到编码时,我总是在网上搜索答案。嗯 我想知道如何用PHP中的其他内容更改文件中的特定行 我有4行代码如下所示: $2y$10$hashedpassword typewar typewarMMM36634573323 84.2xx.xxx.xxx 我最近开始研究cookie之类的东西,希望能够在用户登录到服务器或进入index.php时更改cookie(第3行) 我猜是这样的 $user = 'typewar'; $GeneratedCookie = $us

实际上,我在网上找不到任何答案。当涉及到编码时,我总是在网上搜索答案。嗯

我想知道如何用PHP中的其他内容更改文件中的特定行

我有4行代码如下所示:

$2y$10$hashedpassword
typewar
typewarMMM36634573323
84.2xx.xxx.xxx
我最近开始研究cookie之类的东西,希望能够在用户登录到服务器或进入index.php时更改cookie(第3行)

我猜是这样的

$user = 'typewar';
$GeneratedCookie = $user . 'MMM' . date('H', time()) * date('i', time()) * 333;
$lines = file('/path/to/identity/' . $user . '/identity.txt');
str_replace($lines[2], $GeneratedCookie . '/n');

请帮忙。

我对你的情况不太确定。请找出下面的想法并检查一下

$user = 'typewar';
$GeneratedCookie = $user . 'MMM' . date('H', time()) * date('i', time()) * 333;
$lines = file('/path/to/identity/' . $user . '/identity.txt');
print_r($lines); 
$lines[2] = $GeneratedCookie;
print_r($lines);

如何执行该函数?只需将代码片段与代码和
echo$行集成即可
内爆前后
function.ok,我尝试了:echo内爆('/n',$lines\u arr1);它给了我cookie,现在我如何将它保存到第3行的文件中?内爆前的输出是什么?如果你是说$lines_arr[2],给了我同样的东西。当你尝试该代码时会发生什么?@AndrewMortimer没有任何线索,因为这只是我认为代码可能是什么样子的一个示例。我为此挣扎了一段时间,我甚至不想再测试这个了哈哈