ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This is driving me insane. All i want to do is just display the contents of a file on a .php page.. But not messing up any indentation or anything.. (just like directly reading from the file)
I tried absolutely everything, but the closest i could ever get to is displaying everything in one line..
So far i have,
Code:
<?php
$listFile = "Changelog";
if (!($fp = fopen($listFile, "r")))
exit("Unable to open the input file, $listFile.");
$buffer = fread($fp, filesize($listFile));
print "$buffer<br>\n";
fclose($fp);
?>
Which i managed to find online, but it still doesn't display the file properly.. I don't know what's wrong, please help.
I wouldn't have guessed this without your help.. well, not for the next 3 nights. One annoying thing though.. The file contains some email addresses in the form of
<email@email.com>
, and they're not showing up at all ?! I'm guessing it's not liking the use of < >
OK...
If you do a "View source of your PHP page you'll see the address is there but the angle brakcets make it look like a tag to the browser.
Strip out the brackets and your're in business...
Code:
<pre>
<?php
$listFile = "data.txt";
if (!($fp = fopen($listFile, "r")))
exit("Unable to open the input file, $listFile.");
$buffer = fread($fp, filesize($listFile));
$gtlt = array("<", ">");
$buffer = str_replace($gtlt, "", $buffer);
print "$buffer<br>\n";
fclose($fp);
?>
</pre>
Quick question: Is there a reason you wouldn't simply use an "include('$filename')" command? Just curious - I use this alot to spit out chunks of HTML on a web page; I assume you're wanting to do the same thing?
Apologies if I've not understood what you're trying to do
pnellesen, deiussum, I followed the above code because i've never programmed php before.
All i need to do is this. I have a changelog in a text file, which i want to display to the users. So instead of just displaying dull text from a textfile, say
mysite.com/file.txt
i want to stick it in an html file, surround it with a frame, make it look sexier..
So far, the php code above works. However, if you all think there are better ways in doing so, i'm open for suggestions.
I've added <pre> </pre> to the code above, and it works nicely.
While i still have the interest of some talented programmers Is there a way i can increase the font size of the output, without interfearing with the original text file?
And mind you, this probably is the last question i'll ask for now
I meen, take a base php file of
Code:
<body>
<pre>
<?php
$listFile = "Changelog";
if (!($fp = fopen($listFile, "r")))
exit("Unable to open the input file, $listFile.");
$buffer = fread($fp, filesize($listFile));
$buffer = htmlentities($buffer);
print "$buffer<br>\n";
fclose($fp);
?>
</pre>
</body>
If i change it to,
Code:
<body> <font size="3" face="Verdana" class="text"><span class="style1"> <pre>
<?php
$listFile = "Changelog";
if (!($fp = fopen($listFile, "r")))
exit("Unable to open the input file, $listFile.");
$buffer = fread($fp, filesize($listFile));
$buffer = htmlentities($buffer);
print "$buffer<br>\n";
fclose($fp);
?>
</pre> </font> </body>
It would still display the resulting output the same original size it is in.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.