Status
Not open for further replies.
6 comments
Ignore the previous comment. This is how to do it.


Code:
<?php

echo ".body{";
echo "    background-color:". get_background_color() .";";
echo "    background-image: url(". get_background_image() .");";
echo "}";

?>


This is a short example. Be sure to define seperate functions for each property.
 
Very bad example somik. Also Halcyon was correct in what he said.
Here is a proper example ..
PHP:
<?php
echo <<<HTML
<html>
<head>
<style>

a { display: block; }
p { display: inline; }

</style>
</head>
<body>
<h2>CSS Display</h2>
<a href="http://www.tizag.com/" target="_blank" class="disp1">Tizag.com - Learn to Whip the Web</a>
<a href="http://www.tizag.com/" target="_blank" class="disp1">Tizag.com - Learn to Whip the Web</a>
<a href="http://www.tizag.com/" target="_blank" class="disp1">Tizag.com - Learn to Whip the Web</a>
<a href="http://www.tizag.com/" target="_blank" class="disp1">Tizag.com - Learn to Whip the Web</a>
<a href="http://www.tizag.com/" target="_blank" class="disp1">Tizag.com - Learn to Whip the Web</a>
<br />
	<p class="disp1">These paragraph </p>
	<p class="disp1">elements </p>
	<p class="disp1">have been </p>
	<p class="disp1">inlined.</p>
</body>
</html>
HTML;
?>
 
Very bad example somik.

LOL!



Okies, so this is how i usually write the codes:

PHP:
<?php

/**
 * @author Somik
 * @copyright 2012
 */

// main PHP codes goes here

setcookie("test",$testvalue);

?>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="content-type" content="text/html" />
	<meta name="author" content="Somik" />

	<title>Untitled 2</title>
    <style type="text/css">
    body{
        background-color: black;
        background-image: url(/path/to/image.jpg);
    }
    .tbl_main{
        border: 0px;
        border-collapse: collapse;
    }
    </style>
    <script type="text/javascript">
    // Javascript goes here
    </script>
</head>

<body>

<table class="tbl_main">
  <tr>
    <td>
      <?php echo $value[1]; ?>
    </td>
    <td>
      <?php echo $value[1]; ?>
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <?php myfunction($data1, $data2); ?>
    </td>
  </tr>
</table>


</body>
</html>

<?php

// PHP functions goes here

function myfunction($data1, $data2){
    echo $data1 + $data2;
}

?>


Yes, you can break the php codes with ?> and write HTML, CSS, javascript and whatever you need. Then when you need PHP again, just put it in between PHP tags <?php and ?>

Follow instructions on this site for more info: http://www.tizag.com/phpT/
 
LOL!

Yes, you can break the php codes with ?> and write HTML, CSS, javascript and whatever you need. Then when you need PHP again, just put it in between PHP tags <?php and ?>

Follow instructions on this site for more info: http://www.tizag.com/phpT/


No wonder why I end up in a mess whenever I see your codes!

It is a good practice to separate the html and the server side activities. Coz the user doesn't need to know what happens when he/she loads a page!

MVC pattern (en.wikipedia.org/wiki/Model–view–controllerhttp://en.wikipedia.org/wiki/Model–view–controller) was introduced to take care of this in the first place.


P.S: You need not introduce MVC concepts in a small application (or script) but it may help you out in the long run :)
 
Status
Not open for further replies.
Back
Top