Hi all, I found this little php script to help me render from a text file. The text is readable when rendered, but it seems to completely disregard my CSS. I am unfamiliar with php.
could someone instruct me where I am going wrong please.
What CSS? There is not one bit of CSS in your post.
Yes I understand that. The CSS is in a file.css. What my question is, is that the php script completely ignores any styling. Why?
Without knowing what is in your text file and what the rest of your HTML is no one is going to be able to help you.
CSS does not style PHP
CSS styles HTML
PHP outputs HTML
I’m guessing the HTML the browser gets is incorrect in some way.
If you look at the view-source of a page does the HTML look like you would expect it to?
A sensible answer at least. Thanks. The browser renders everything ok, except with that script. The HTML I wrote myself, and the source is good. Could you please instruct me as to why that bit of php code bypasses my CSS. Or at least how I can correct it. Thanks.
The txt file contains words nothing else. The rest of the HTML works fine.
If you are reluctant to supply the actual “words nothing else” then please supply alternative text instead and usage.
I am intrigued with your problem because I use the PHP text file technique frequently.
Edit:
Just tested this on my desktop and it works fine:
<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1');
?>
<!doctype html><html lang="en">
<head>
<title> asdf </title>
<style>
.fred {
font-weight:700;
font-style: italic;
color:green;
}
</style>
</head>
<body>
<div class="fred">
<?php
$content = file('kill.txt');
$data = implode('<br><br>', $content);
echo $data;
?>
</div>
</body>
</html>
Output:
Could you make sure the file type (bin, ascii, utf, iso…) is recognized
by the loader?
Is the content’s character set what the loader expect?
Is the file.css processed and included but with no content?
Just trying to understand the issue.
Ok. I see you have styled the text in the header, whereas I use a CSS file pointed to in the header. Thank you, you have given me something to try. Much appreciated.
Try this on your localhost:
<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1');
$info = 'https://gekkobooks.tk/assets/css/style.min.css?refresh=1574227187';
?><!doctype html><html lang="en">
<head>
<title> asdf </title>
<link type="text/css" href="https://gekkobooks.tk/assets/css/style.min.css?refresh=1574227187" media="screen" rel="stylesheet"/>
</head>
<body class="bgQ">
<div class="mga tac">
<div class="fsl fwb bgy fgr tac dib">
<?php
$content = file('kill.txt');
$data = implode('<br><br>', $content);
echo $data;
?>
</div>
</div>
</body>
</html>
Output:
Edit:
Just realised a file name by the name of “kill.txt”, in the same directory is essential with names on a separate line is essential.
[off-topic]
All files and directories beginning with kill can be safely deleted is a throwback from when disk-space was severely limited.
[/off-topic]
If the file is just text, that script is going to output text, broken into lines with the <br>
tags insire a div
with the class content
.
So this is just a case of applying the desired styling to content
:-
.content {
/* Styles for your text here */
}
Or is this hat you have and is not working?
Generally in the html & css forum, it’s best just to post the resultant html code (plus any relavant css) from your php instead of the php. That gives a better indication of the actual content being dealt with. HTML & CSS are pretty much back-end agnostic.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.