source: branches/testa-single-bookmark/php/func.php @ 111

Last change on this file since 111 was 61, checked in by anonymous, 6 years ago

fix error in fopen

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1<?php
2function 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
21function get_fname( $name ){
22        $str = "";
23       
24        if($_SERVER['REQUEST_METHOD'] == "POST"){
25                $str = $_POST[$name];      // テキストエリアの値を取得
26        }
27        return $str;
28}
29
30function 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
39function output_file( $fname , $content ) {
40        $file = fopen($fname, "w");
41    if( $file !== FAlSE ){
42        fwrite( $file, $content . "\n" );
43        fflush($file);
44        fclose($file);
45    }
46}
47
48function input_file( $fname ) {
49        $file = fopen($fname, "r");
50    $content = "";
51    if( $file !== FAlSE ){
52        $content = fread( $file, filesize($fname) );
53        fclose($file);
54    }
55        return $content;
56}
57
58
59?>
Note: See TracBrowser for help on using the repository browser.