General Community > Scripting Help
text lf question
(1/1)
andrea:
How to include a text file such that the line separators contained in the text file are parsed?
Example:
http://www.yabbse.org/community/attachments/YaBB_SE_modifications_TOS.txt
There you see the text has some line delimiters. Now I include this text in a php file with this simple code:
--- Code: ---<?php
include("http://www.yabbse.org/community/attachments/YaBB_SE_modifications_TOS.txt");
?>
--- End code ---
The output of this php file you see here:
http://hubacher.net/yabbse-mod-tos.php
Alle line delimiters, feeders etc. are gone. What am I doing wrong? I did already try to store the text file on my local server disk and include from there, this did not help.
Zef Hemel:
Beside the fact that it's very inefficient to use inlcude with URLs, you should always use paths if possible. This might work:
--- Code: ---<?php
echo nl2br(implode('', file('http://www.yabbse.org/community/attachments/YaBB_SE_modifications_TOS.txt')));
?>
--- End code ---
[Unknown]:
--- Quote from: Zef Hemel on August 17, 2003, 10:57:52 AM ---Beside the fact that it's very inefficient to use inlcude with URLs, you should always use paths if possible. This might work:
--- Code: ---<?php
echo nl2br(implode('', file('http://www.yabbse.org/community/attachments/YaBB_SE_modifications_TOS.txt')));
?>
--- End code ---
--- End quote ---
I would personally do it like this...
--- Code: ---echo nl2br(htmlspecialchars(implode('', file('http://www.yabbse.org/community/attachments/YaBB_SE_modifications_TOS.txt'))));
--- End code ---
Or, for versions of PHP above 4.3.x...
--- Code: ---echo nl2br(htmlspecialchars(file_get_contents('http://www.yabbse.org/community/attachments/YaBB_SE_modifications_TOS.txt')));
--- End code ---
-[Unknown]
Aquilo:
I guess these php books might come in handy I never knew about the nl2br() function :(
I would have done the fopen, while loop, and str_replace thing :P
what would be the BEST php book?
Spaceman-Spiff:
Suggested Books to learn Php & MySQL
Navigation
[0] Message Index
Go to full version