回答編集履歴
1
修正
test
CHANGED
@@ -25,3 +25,59 @@
|
|
25
25
|
もし最後の手前のデータまで正常に取得できていたとしても、最後のデータがとれていなければ空になります。
|
26
26
|
|
27
27
|
デバッグ兼ねて、ループできている文字列を含めてfile_put_contents()の第3引数に`FILE_APPEND`をつけておくと「どこまでできているか」の問題切り分けが可能になります。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
デバッグコードを入れた例:
|
32
|
+
|
33
|
+
```php
|
34
|
+
|
35
|
+
$directory_paths = $_POST['listData'];
|
36
|
+
|
37
|
+
$boforeText = 'アハハ';
|
38
|
+
|
39
|
+
$afterText = 'ウフフ';
|
40
|
+
|
41
|
+
$updated_date = '190101';
|
42
|
+
|
43
|
+
foreach($directory_paths as $index=>$path){
|
44
|
+
|
45
|
+
if(!file_exists($path)){
|
46
|
+
|
47
|
+
echo $path.": not exists.".PHP_EOL;
|
48
|
+
|
49
|
+
}else{
|
50
|
+
|
51
|
+
echo $path.": exists.".PHP_EOL;
|
52
|
+
|
53
|
+
$pathData = pathinfo($path);
|
54
|
+
|
55
|
+
//書き込み先ファイル名
|
56
|
+
|
57
|
+
$writing_file = $pathData["dirname"].'/'.$updated_date.'_'.$index.'.html';
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
$content = file_get_contents($path);
|
62
|
+
|
63
|
+
if(!$content){
|
64
|
+
|
65
|
+
echo $path.": can not get the content.".PHP_EOL;
|
66
|
+
|
67
|
+
}else{
|
68
|
+
|
69
|
+
echo $path.": can get the content.".PHP_EOL;
|
70
|
+
|
71
|
+
$replace = str_replace($boforeText, $afterText, $content);
|
72
|
+
|
73
|
+
file_put_contents($path.PHP_EOL.$writing_file, $replace);
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
```
|