CSS and PHP

This is a discussion on "CSS and PHP" within the PHP Forum section. This forum, and the thread "CSS and PHP are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 6th, 2007, 21:47
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
CSS and PHP

How do I insert css style sheets in php, and if the sylesteet has a fixed text body will the php stay in that area?
Reply With Quote

  #2 (permalink)  
Old Aug 6th, 2007, 22:30
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: CSS and PHP

What? Are you trying to use PHP to dynamically add style sheets?

What exactly are you asking?
Reply With Quote
  #3 (permalink)  
Old Aug 6th, 2007, 23:09
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS and PHP

How Do I Put Css in Php
Reply With Quote
  #4 (permalink)  
Old Aug 6th, 2007, 23:15
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: CSS and PHP

I don't think you can actually style PHP. It's a programming language. What you can style is HTML that PHP outputs.

If your asking how to style the output from PHP then I think you'll have to post a better description of what your trying to do. Or maybe some code.

Sorry if I'm still not getting what your trying to say here.
Reply With Quote
  #5 (permalink)  
Old Aug 6th, 2007, 23:27
acrikey's Avatar
SuperMember

SuperMember
Join Date: Mar 2007
Location: UK
Posts: 305
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS and PHP

Ok how do I put php in html
Reply With Quote
  #6 (permalink)  
Old Aug 6th, 2007, 23:43
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: CSS and PHP

Em. Well. Something like this I guess...

PHP: Select all


<html>
<head>
<?php

$style 
'<link rel="stylesheet" type="text/css" href="style.css" />';
$title 'Page Title';
$class 'myClass';

echo $ 
style;

?>
</head>
<body>
<h1 class="<?php echo $class?>"><?php echo $title?></h1>

<p>content</p>

</body>
</html>
That is how you would put PHP with a html document (must have a .php extension). Just wrap all your php code in "<?php ?>" tags.

If you understand PHP you can style your content dynamically as well by echoing classes and using variables sort of like how I have done above.
Reply With Quote
  #7 (permalink)  
Old Aug 9th, 2007, 13:36
Junior Member
Join Date: Aug 2007
Location: London
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Re: CSS and PHP

As a convenience when wanting to embed values of variables within HTML, you can also use <?=

So instead of

Code: Select all
<h1 class="<?php echo $class; ?>"><?php echo $title; ?></h1>


you could write

Code: Select all
<h1 class="<?=$class?>"><?=$title?></h1>


If you get really keen on PHP and plan to use it for serious work then it's good practice to separate your business logic from presentation logic as much as possible. If database queries and other computational code is mixed in with the HTML code then it can make it much harder to maintain the codebase, and in the worst case, impossible. Spaghetti code also increases the probability of bugs and complicates debugging.

Template systems such as Smarty can be helpful as can frameworks such as CakePHP. Most frameworks offer additional benefits to merely using templates by encouraging certain design practices and consistency, and they can also substantially reduce the amount of code that is required to be written.

Last edited by ioncube; Aug 9th, 2007 at 13:40.
Reply With Quote
Reply

Tags
css, php

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 05:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43