| [23] | 1 | <?php |
|---|
| 2 | function get_lines_from_formdata( $name ) { |
|---|
| 3 | $lines_array = array(); |
|---|
| 4 | |
|---|
| 5 | if($_SERVER['REQUEST_METHOD'] == "POST"){ |
|---|
| 6 | $str = $_POST[$name]; // テキストエリアの値を取得 |
|---|
| 7 | $cr = array("\r\n", "\r"); // 改行コード置換用配列を作成しておく |
|---|
| 8 | |
|---|
| 9 | $str = trim($str); // 文頭文末の空白を削除 |
|---|
| 10 | |
|---|
| 11 | // 改行コードを統一 |
|---|
| 12 | //str_replace ("検索文字列", "置換え文字列", "対象文字列"); |
|---|
| 13 | $str = str_replace($cr, "\n", $str); |
|---|
| 14 | |
|---|
| 15 | //改行コードで分割(結果は配列に入る) |
|---|
| 16 | $lines_array = explode("\n", $str); |
|---|
| 17 | } |
|---|
| 18 | return $lines_array; |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | function get_fname( $name ){ |
|---|
| 22 | $str = ""; |
|---|
| 23 | |
|---|
| 24 | if($_SERVER['REQUEST_METHOD'] == "POST"){ |
|---|
| 25 | $str = $_POST[$name]; // テキストエリアの値を取得 |
|---|
| 26 | } |
|---|
| 27 | return $str; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | function output_file_from_lines( $fname , $lines ) { |
|---|
| 31 | $file = fopen($fname, "w"); |
|---|
| 32 | foreach($lines as $line){ |
|---|
| 33 | fwrite( $file, $line . "\n" ); |
|---|
| 34 | } |
|---|
| 35 | fflush($file); |
|---|
| 36 | fclose($file); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | function output_file( $fname , $content ) { |
|---|
| 40 | $file = fopen($fname, "w"); |
|---|
| [51] | 41 | if( $file !== FAlSE ){ |
|---|
| 42 | fwrite( $file, $content . "\n" ); |
|---|
| 43 | fflush($file); |
|---|
| 44 | fclose($file); |
|---|
| 45 | } |
|---|
| [23] | 46 | } |
|---|
| 47 | |
|---|
| 48 | function input_file( $fname ) { |
|---|
| 49 | $file = fopen($fname, "r"); |
|---|
| 50 | $content = fread( $file, filesize($fname) ); |
|---|
| 51 | fclose($file); |
|---|
| 52 | |
|---|
| 53 | return $content; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | ?> |
|---|