解析错误:语法错误,第9行代码中的意外'(',期望变量(T_VARIABLE)或'$'[重复]
问题描述:
This question already has an answer here:
<?php
$name = $_POST['name'];
$price = $_POST['price'];
$absolute_path = "/Plants/List/index.html";
$PlantFile = fopen($_SERVER['DOCUMENT_ROOT'] . "$absolute_path", "a") or die("Unable to open file!");
$trimmedname = preg_replace('/\s+/', '', $name);
fwrite($PlantFile, "
<div class='wrapper one $trimmedname' id='main'>
<h1>$name</h1>
<p>Price: $price</p>
<?php if($_SESSION[id]) {?>
<button>Delete $name</button>
<script> var simple = \"<?php echo $trimmedname; ?>\"; $(\"button\").click(function(){$(simple).remove();}); </script>
<?php } ?>
</div>
");
fclose($PlantFile);
?>
I keep getting the error:
Parse error: syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$' in your code on line 9
Could anyone help? Thanks guys!
</div>
此问题已经存在 这里有一个答案: p>
-
PHP解析/语法错误; 以及如何解决它们?
17 answers
span>
li>
ul>
div>
&lt;?php $ name = $ _POST ['name']; $ price = $ _POST ['price']; $ absolute_path =“/ Plants /List / index.html”; nnnPlantFile = fopen($ _ SERVER ['DOCUMENT_ROOT']。“$ absolute_path”,“a”) 或者死掉(“无法打开文件!”); $ trimmedname = preg_replace('/ \ s + /','',$ name); nfwrite($ PlantFile,“ &lt; div class ='wrapper 一个$ trimmedname'id ='main'&gt; &lt; h1&gt; $ name&lt; / h1&gt; &lt; p&gt;价格:$ price&lt; / p&gt; &lt;?php if($ _ SESSION [id]){ ?&gt; &lt; button&gt;删除$ name&lt; / button&gt; &lt; script&gt; var simple = \“&lt;?php echo $ trimmedname;?&gt; \”; $(\“button \”)。click( function(){$(simple).remove();});&lt; / script&gt; &lt;?php}?&gt; &lt; / div&gt; “); nclclose($ PlantFile) ; ?&gt; code> pre>
我一直收到错误: p>
P 屁股错误:语法错误,第9行代码中的意外'(',期望变量(T_VARIABLE)或'$' p> blockquote>
任何人都可以提供帮助吗? 谢谢你们! p> div>
答
I think the problem lies in your use of the curly braces in combination with the $
sign aka {$(simple).remove();}
.
try replacing $
with \$
so that your jQuery
$
sign wont be treated as a php variable.