PHP 7.1.19
macOS mojave
サーバにソケットを接続して"/index.html"のドキュメントとヘッダを出力するコードなのですが、エラーが解消できません。問題点のご指摘をお願いします。
PHP
1<html> 2 3<head> 4 <meta http-equiv="content-type" content="text/html;charset=utf-8"> 5</head> 6 7 8<body> 9 <? php 10 11 $hostname="www.google.co.jp"; 12 $fp = fsockopen($hostname,80,$errno,$errstr); 13 soket_set_timeout($fp,10); 14 $request="GET /index.html HTTP/1.0\r\n\r\n"; 15 fputs($fp,$request); 16 17 $response =""; 18 19 while(!feof($fp)){ 20 $response.=fgets($fp,4096); 21 } 22 23 fclose($fp); 24 echo $response; 25 26 ?> 27</body> 28 29</html>
error
1Parse error: syntax error, unexpected '$hostname' (T_VARIABLE) in socket.php on line 11
11行目は以下の箇所です。
$hostname="www.google.co.jp";
回答2件
あなたの回答
tips
プレビュー