Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need insert some PHP code in style sheet

Tags:

css

php

In my css

div.image {
   width:<?php echo get_image_size( $size[1] ); ?>px;
}

The size is stored in an array so i called $size[1] to here...

I am beginner in php...

any one pls help?

like image 264
Dhamu Avatar asked Apr 26 '12 12:04

Dhamu


People also ask

Can we add PHP code in CSS file?

Putting PHP code in a CSS file will not work. You will have to create a PHP file first, and let that output CSS code. And also set the correct content type headers.

Where do I write PHP code in HTML file?

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the PHP. Step 2: Now, we have to place the cursor in any tag of the <body> tag where we want to add the code of PHP. And, then we have to type the start and end tag of PHP.

Can I include PHP in HTML?

PHP is designed to interact with HTML and PHP scripts can be included in an HTML page without a problem.

How do I style a form in PHP?

There is no way to style within PHP. You can either put your CSS in a separate file and link to it with a <link> tag or you could put it in <style> tags in the head of the document and then using class="mycssclass" , or you put it as a style attribute within the HTML​.


1 Answers

Better solution is to set a header for the css / php file in my example cssfile.php:

<?php header("Content-type: text/css"); ?>

Then you can use the php file as style.

<link rel="stylesheet" type="text/css" href="cssfile.php?param=1" />

Then you should get the output on your site. But with that solution you should be very careful if you have a lot of traffic. On every site call your PHP interpreter is used to deliver that file.

like image 189
René Höhle Avatar answered Sep 22 '22 16:09

René Höhle