javascript - Storing the contents of an external php stylesheet in html -


i have php file that's being used dynamic stylesheet. large file css/values generated php. here's example.

<?php header("content-type: text/css"); ?> .top {     top: <?= $topvalue ?>px; } more css... 

on separate file, i'm trying generated content php file , store on page somewhere can later javascript. method i'm trying storing contents in hidden input. so.

<?php $file = file_get_contents("file_url.php"); ?> <input type="hidden" name="hidden-css" value="<?= $file ?>" /> 

however, when this, value contains raw php file , commenting out opening/closing php tags. instance, doing things '< !--?php' instead of "< ?php" , "?-->" instead of "?>". messes general html on page , doesn't store value correctly in input.

so ask you, how can fix current situation or better store contents of stylesheet on page can later grab , use javascript?

edit: there may issue quotes in generated css causing issues. i'm not sure how address issue either.

edit: how should stored if worked perfectly.

<input type="hidden" name="hidden-css" value=" .top { top: 54px; } " />  

you can't use file_get_contents() function purpose - gets file contents (i.e. won't run php on file first).

instead, user574632 suggests, must use include , code this:

<input type="hidden" name="hidden-css" value="<?php include 'file_url.php'; ?>" /> 


hopefully solves problem.


(another quick note: given main file html not css, need declare content header again after input this:

<?php header('content-type: text/html; charset=utf-8'); ?> 

)


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -