解析错误:语法错误,第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>

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.