markie markie - 1 month ago 4x
PHP Question

PHP - include/require/insert some data from one file to another

I'm not really familiar with php and would like to ask you to help me.

I want to insert

styling data from
file into the
tag inside of
, and not sure how to do so with secure and optimized way.

Should I use
<?php include 'styles.css;?>
<?php require 'styles.css;?>
or what exactly should I do in order to insert the data in the optimized and secure way, please?


require/include is for parsing a PHP file, not copying content.

Just read the file and echo the contents.

<?= file_get_contents('styles.css') ?>

where <?= is a shorthand for <?php echo. See also: HTML output from web server

Note that the include path in PHP environment may be different from that in the HTML, as understood by the browser. Better use __DIR__ . '/styles.css' to prevent problems.