teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

書き間違い

2016/10/27 08:46

投稿

mizugasira
mizugasira

スコア29

answer CHANGED
@@ -1,14 +1,15 @@
1
1
  ```php
2
2
  <?php
3
3
  //対象ファイルはこちら
4
- $file = "http://www.city.omura.nagasaki.jp/index.html";
4
+ $file = "読み取るページのURL";
5
5
  //ファイルソースを文字列として所得
6
6
  $file_content = file_get_contents($file);
7
7
  //その中に画像パスがあるか検索します
8
- preg_match_all('/<img.*src\s*=\s*[\"|\'](.*?)[\"|\'].*>/i', file_get_contents($file), $img_path_list);
8
+ preg_match_all('/<img.*src\s*=\s*[\"|\'](.*?)[\"|\'].*>/i', $file_content, $img_path_list);
9
9
  header('Content-type: image/jpeg');
10
- //表示します
10
+ // 表示します
11
+ // 自分の場合こうなりましたが、配列の中身が違うこともあります。
11
- $img_path_list[1][0] = 'http://www.city.omura.nagasaki.jp' . $img_path_list[1][0];
12
+ $img_path_list[1][0] = 'http://xxxx.co.jp' . $img_path_list[1][0];
12
13
 
13
14
  readfile($img_path_list[1][0]);
14
15