Page 1 of 1

CSS styles not seen in php

Posted: Thu Sep 24, 2009 4:28 pm
by agapetos
Hello!
I have just finished making a .php file that is supposed to search mysql database. I works all right, I mean... it can print all data in a table, but since I want it to look nice, and not just ordered in table, I don't know how to do it.
I already know how it should look like, and how it would be possible in html, but since this is inside <php> brackets and inside WHILE LOOP, for some reason when I enter this:

Code: Select all

echo "<div style="padding:25px"> [i]some text, variables or values[/i] </div>";
it just doesn't work. Same is if I use print instead of echo.
Now... if I just type plain:

Code: Select all

echo "<div> [i]some text, variables or values[/i] </div>";
it works nicely, but I didn't succeed anything that way. What I want is that I am able to manipulate with CSS styles.
Do you know maybe if it is a rule that I can't introduce CSS styles inside PHP brackets?

P.S: I really didn't know where did this subject belong to, PHP code or CSS, so I am sorry if I mistakenly missplaced this.

Re: CSS styles not seen in php

Posted: Thu Sep 24, 2009 4:48 pm
by kaszu
It doesn't work because of the quotes, do you have errors turned off?! Correct:

Code: Select all

echo '<div style="padding:25px"> some text, variables or values </div>';
//or
echo "<div style=\"padding:25px\"> some text, variables or values </div>";
A better solution would be to use class="..." attribute and .css file instead of style="..."

If you had used

Code: Select all

then you would see your error after posting

Re: CSS styles not seen in php

Posted: Thu Sep 24, 2009 7:08 pm
by califdon
As kaszu said, you can't have a quoted string within another quoted string using the same (single or double) quote characters unless you "escape" them with a backslash. The reason I'm chiming in here is just to point out to you that there is nothing "special" about what you can do within a PHP code block, other than that you must either echo or print anything that you want to be sent to the browser. PHP simply has the capability to determine what HTML/CSS/Javascript code you want to send to the browser. Once it gets to the browser, HTML is HTML, CSS is CSS, Javascript is Javascript, it doesn't matter whether it came from within a PHP code block or not. Indeed, there's no way to tell whether it did or not.