麻烦小的PHP函数Http Error 500

jma*_*ris 0 php http

我只是学习php,练习我想尝试制作一个可以在文档中轻松生成CSS3渐变的php函数.

我遇到HTTP错误500.这是代码:

<?php
function cgrad($c1,$c2,$applyto)
{
echo 
"<style type="text/css">
$applyto {
background-image: -ms-linear-gradient(top, $c1 0%, $c2 100%);
background-image: -moz-linear-gradient(top, $c1 0%, $c2 100%);
background-image: -o-linear-gradient(top, $c1 0%, $c2 100%); 
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, $c1), color-stop(1, $c2));
background-image: -webkit-linear-gradient(top, $c1 0%, $c2 100%);
background-image: linear-gradient(to bottom, $c1 0%, $c2 100%);
height : 100%;
width : 100%;}
</style>";
};
?>
<html>
<head>
<?php
cgrad(#FFFFFF,#000000,body);
?>
</head>
<body>
testing
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

任何帮助深表感谢.

Roc*_*mat 5

echo 
"<style type="text/css">
Run Code Online (Sandbox Code Playgroud)

你不能在双引号内加双引号.你可以逃脱它们(就像其他答案所说)或使用单引号.

echo 
"<style type='text/css'>
Run Code Online (Sandbox Code Playgroud)

此外,您在通话时需要报价cgrad.

<?php
cgrad('#FFFFFF','#000000','body');
?>
Run Code Online (Sandbox Code Playgroud)