Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to style php echo output

Tags:

css

php

It's probably stupid question, but I can not find an answer. How can I style echo output with css? I have this code:

echo "<div id="errormsg"> Error </div>";

Now it displays syntax error, I think because of those quotes around errormsg. I've tried single quotes, but with no effect. Thank you

like image 765
culter Avatar asked Aug 22 '11 12:08

culter


3 Answers

When outputting HTML, it's easier to use single quotes so you can use proper double quotes inside like so:

echo '<div id="errormsg"> Error </div>';

That will get rid of your parse error... To edit the style you will need to use CSS with the selector of #errormsg like so:

#errormsg {
    color: red;
}
like image 99
Dunhamzzz Avatar answered Sep 20 '22 22:09

Dunhamzzz


try

echo "<div id=\"errormsg\"> Error </div>";
like image 39
Napas Avatar answered Sep 20 '22 22:09

Napas


First you need to either use single-quotes to surround the attribute value:

echo "<div id='errormsg'> Error </div>";

Or you could reverse that, to give:

echo '<div id="errormsg"> Error </div>';

Or you should escape the quotes:

echo "<div id=\"errormsg\"> Error </div>";

And then style the resulting element with the CSS:

#errormsg {
    /* css */
}

The syntax problem you were encountering is a result of terminating the string and then having a disparate element between the first and second strings, with which PHP has no idea what to do.

like image 43
David Thomas Avatar answered Sep 22 '22 22:09

David Thomas