Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $file = "data.txt";
- function get_data()
- {
- global $file;
- $data = "";
- if( !file_exists($file) )
- {
- return $data;
- }
- $data = file_get_contents($file);
- return $data;
- }
- var_dump(get_data());
- function add_new_item( $txt )
- {
- global $file;
- $data = get_data();
- $data = $data . $txt . "<br>\r\n";
- $fp = fopen($file, "w");
- fwrite($fp, $data );
- fclose($fp);
- }
- if( isset( $_POST['submit'] ) )
- {
- $txt = $_POST['item'];
- add_new_item( $txt );
- }
- ?>
- <form action="" method="post">
- Name : <input type="text" name="item" />
- <input type="submit" name="submit" value="Save" />
- </form>
- <h3>All Data</h3>
- <?php
- echo get_data();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement