回答編集履歴

1

サンプルソースの整形

2015/03/01 16:22

投稿

hayashi_kohei
hayashi_kohei

スコア47

test CHANGED
@@ -1,35 +1,41 @@
1
- User-Agentを追加してみました。これで取れますでしょうか?
1
+ User-Agentをheaderに追加してみました。
2
+
3
+ これで取れると思います。
2
4
 
3
5
 
4
6
 
5
- 1 <?php
7
+ ```lang-php
6
8
 
7
- 2
9
+ <?php
8
10
 
9
- 3 $html = file_get_contents( "http://jp.eurail.com/trains-europe/high-speed-trains/ice" );
11
+ $html = file_get_contents( "http://jp.eurail.com/trains-europe/high-speed-trains/ice" );
10
12
 
11
- 4
12
13
 
13
- 5 $opt = array(
14
14
 
15
- 6 'http'=>array(
15
+ $opt = array(
16
16
 
17
- 7 'metho'=>'GET',
17
+ 'http'=>array(
18
18
 
19
- 8 'header'=>'User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1'
19
+ 'metho'=>'GET',
20
20
 
21
- 9 )
21
+ 'header'=>'User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1'
22
22
 
23
- 10 );
23
+ )
24
24
 
25
- 11
25
+ );
26
26
 
27
- 12 $context = stream_context_create( $opt );
28
27
 
29
- 13
30
28
 
31
- 14 $html = file_get_contents( "http://jp.eurail.com/trains-europe/high-speed-trains/ice", false, $context );
29
+ $context = stream_context_create( $opt );
32
30
 
33
- 15
34
31
 
32
+
33
+ $html = file_get_contents( "http://jp.eurail.com/trains-europe/high-speed-trains/ice", false, $context );
34
+
35
+
36
+
35
- 16 echo $html;
37
+ echo $html;
38
+
39
+
40
+
41
+ ```