Parse error T_Variable [closed]

2019-02-21 06:07发布

This is my code:

 <? php
 $content = file_get_contents("http://aux.iconpedia.net/uploads/1337412470.png");
 $fp = fopen("/test/image.jpg", "w");
 fwrite($fp, $content);
 fclose($fp);
 ?>

And this is the error I get:

Parse error: syntax error, unexpected T_VARIABLE in D:\Host\5164\html\maffick1\test\download.php on line 2

As far as I know, this error comes when you miss semicolon or bracket. But I have tried everything. Please help me.

标签: php parsing
2条回答
我命由我不由天
2楼-- · 2019-02-21 06:38

Since <? also marks the beginning of a PHP script, the parser will treat your code as:

 <?
 php
 $content = file_get_contents("http://aux.iconpedia.net/uploads/1337412470.png");
 $fp = fopen("/test/image.jpg", "w");
 fwrite($fp, $content);
 fclose($fp);
 ?>

So it believes you're trying to declare a variable called php, but it's missing the $ sign.

Remove the space:

 <?php
 $content = file_get_contents("http://aux.iconpedia.net/uploads/1337412470.png");
 $fp = fopen("/test/image.jpg", "w");
 fwrite($fp, $content);
 fclose($fp);
 ?>
查看更多
时光不老,我们不散
3楼-- · 2019-02-21 06:54

Remove space between question mark and "php" in first line:

<? php

Change this to:

<?php
查看更多
登录 后发表回答