@@ 72-82 (lines=11) @@ | ||
69 | * @param string $string Text to be added in front of the file |
|
70 | * @param string $filename File to prepend in |
|
71 | */ |
|
72 | public static function prepend($string, $filename) |
|
73 | { |
|
74 | $context = stream_context_create(); |
|
75 | $fp = fopen($filename, 'r', 1, $context); |
|
76 | $tmpname = md5($string); |
|
77 | file_put_contents($tmpname, $string); |
|
78 | file_put_contents($tmpname, $fp, FILE_APPEND); |
|
79 | fclose($fp); |
|
80 | unlink($filename); |
|
81 | rename($tmpname, $filename); |
|
82 | } |
|
83 | ||
84 | /** |
|
85 | * Append the string in the file |
|
@@ 90-100 (lines=11) @@ | ||
87 | * @param string $string Text to be added in front of the file |
|
88 | * @param string $filename File to prepend in |
|
89 | */ |
|
90 | public static function append($string, $filename) |
|
91 | { |
|
92 | $context = stream_context_create(); |
|
93 | $fp = fopen($filename, 'r', 1, $context); |
|
94 | $tmpname = md5($string); |
|
95 | file_put_contents($tmpname, $fp); |
|
96 | file_put_contents($tmpname, $string, FILE_APPEND); |
|
97 | fclose($fp); |
|
98 | unlink($filename); |
|
99 | rename($tmpname, $filename); |
|
100 | } |
|
101 | ||
102 | /** |
|
103 | * Find and replace the string in the file |