PHP从特定位置附加到文件 [英] PHP appending to file from specific position

查看:32
本文介绍了PHP从特定位置附加到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 php 中,我打开一个文本文件并附加到它.但是我需要在文件末尾附加 3 个字符.换句话说,我需要从文件中的特定位置追加/写入.

In php i am opening a text file and appending to it. However I need to append 3 chars before the end of file. In other words i need to append/write from a specific place in the file.

有人可以帮忙吗?

最好的问候鲁本

推荐答案

需要打开文件进行编辑,搜索到想要的位置,然后写入文件,例如:

You need to open the file for edit, seek to the desired position and then write to the file, eg.:

<?php
  $file = fopen($filename, "c");
  fseek($file, -3, SEEK_END);
  fwrite($file, "whatever you want to write");
  fclose($file);
?>

进一步参考 php.net - fseek doc

希望有所帮助.

这篇关于PHP从特定位置附加到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆