怎么建一串字符写入某文件的开头

WBOY
Release: 2016-06-13 10:03:43
Original
973 people have browsed it

如何建一串字符写入某文件的开头
假设某文件为a.php
内容为:JJJJJJJJJJJJJJJJJJJJJJJ;
通过程序使a.php 文件开头插入一串字符串的 字符串+JJJJJJJJJJJJJJJJJJJ

------解决方案--------------------
最简单的做法先把文件内容用file_get_contents()读到个字符串里
再在这个字符串前加上你要加的字符串
然后再写回文件a.php
麻烦点的做法就是用fopen(),参数r+
------解决方案--------------------
呵呵
$temp=file_get_contents("a.php");
$add_str="要添加的字符串";
file_put_contents("a.php",$add_str.$temp);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template