0

I'm just learning php, To practice i want to try and make a php function that can generate CSS3 gradients easily in a document.

I am running into HTTP Error 500. here's the code :

<?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>

Any help is much appreciated.

2
  • 1
    HTTP 500 can occur when there are syntax errors in PHP. For future refernce, always check your code for ending semicolons, proper quotes, and things of that nature. Commented Jul 5, 2012 at 16:37
  • Thanks very much to both people who responded, Sorry about it being such a simple problem, Being new to php i didn't notice it. Many thanks Commented Jul 5, 2012 at 16:46

2 Answers 2

5
echo 
"<style type="text/css">

You can't put double quotes inside double quotes. You can either escape them (like the other answers say) or use single quotes.

echo 
"<style type='text/css'>

Also, you need quotes when calling cgrad.

<?php
cgrad('#FFFFFF','#000000','body');
?>
Sign up to request clarification or add additional context in comments.

1 Comment

The cgrad function's parameters need to be quoted because the pound # creates a comment.
2
echo 
"<style type="text/css">

You're using quotes both to delimit your echo statement, and inside it - PHP can't figure out what quotes are which. One way is to escape the quotes inside the echo statement:

echo 
"<style type=\"text/css\">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.