View Full Version : Apply CSS on PHP output?

01-15-2008, 01:27 AM
How can I apply css on my output like tables and colors, bold ,align, etc...
like I want to apply style to the colored section:

here is the code:

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">

<style type="text/css">
.direccion {
text-align: center;
.direccion {
font-family: Arial;

<img src="loguito.jpg" /><div style="float:right;width:400px"><a href="#" onclick="java script:window.print(); return false">Imprimir</a></div> <br /> <br />
<div style="width:600px;text-align:center;border-color:black;text-indent:5px;">

if($_GET['continue'] != 1)
$name = $_GET['class'];

// form items you wish to exclude from the info list. you can just make this blank if you dont want to exclude anything
$exclude = array('submit','hiddenvalue');

foreach($_POST as $class => $val){

// if its in the exclude array, skip it
if(in_array($val, $exclude))

// print out the info
echo $class.":\t\t ".$val."<br />\n";



<br /><br /><br />
<div style="width:600px;text-align:center;border-color:black;text-indent:5px;>
<br /><br /><br /><br /><br />
<li class="direccion"><a href="<?=$_SERVER['PHP_SELF']?>?continue=1">Si su informacion esta correcta click aqui.</a></li>
<br />
<li class="direccion"> <a href="javascript:history.go(-1);">Si quiere hacer algun cambio click aqui. (Volver)</a></li>

<br /><br />

<p class="direccion"><strong><em><span class="style2">Ave. 14 de Julio contiguo a
Ferreteria Casa Siryi.<br>
PO Box: (504) 440-3555</span></em></strong></p>
<p class="direccion"><br>
<a target="_blank" href="http://www.technosdesign.com">www.technosdesign.com</a></p>


// do your "its confirmed code"
// for example, forward the user to a page (uncomment the line):
// header("Location: http://url.com");


01-15-2008, 02:38 AM
I don't understand the problem you are having, this is the correct idea (haven't gone through the code line by line though...).
You have php that is populating html elements and applying the stylesheet to the elements. I see you are using your class in an list element, so it is applied (though the style can be combined into only one declaration). Watch your spelling as well, there is a 'java script:' in one of your calls which will not work. Also, your php calls from the inside of the code:
I would not recommend. This may not work on all servers for starters, and _SERVER['PHP_SELF'] superglobal is also susceptible to XSS injections. A better option would be:
<?php echo $_SERVER['SCRIPT_NAME'];?>
where the two changes are the short tags are removed (<?= to <?php echo) and the semi-colon added at the end (which I believe is required regardless of the method of call).
My final words are: don't develop using MS Office, it is not worth the headache. Although you have pulled it into xml/html code which is good, it will cause you headaches in the long run - especially since it tends to add garbage at the top of all your generated pages, and will kill a php script.

Oh, and I made this assumption which I should not have. I assume that your file has been saved with a .php extension and that you are running it on a host with php capabilities. This won't actually change the stylesheet usage on the page, but obviously it won't parse as php if you don't have these.
Hope that helps!

Hmm, maybe I've completely mistook what you are looking for. I didn't notice that you had no linked stylesheet before.
Assuming you have your stylesheet created (which I will not teach here, but the CSS forum will gladly help), you just link it into your HTML code's <head> tag like so:
<link rel="stylesheet" type="stylesheet" href="path/to/my/stylesheet.css" />
Where stylesheets generally have a .css extension.