include a .txt file
Moderator: General Moderators
-
polishvalor
- Forum Newbie
- Posts: 13
- Joined: Sat Nov 06, 2010 10:45 pm
include a .txt file
I use include for a text file forgetting how to make sure " and ' are shown correctly. Can someone please remind me?
Re: include a .txt file
if your text file is outputting those to the screen put a \ infront of them or use " instead of " in your txt file.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: include a .txt file
You generally only need to apply this when your text is inserted into html elements, where you need to be careful not to break out of the element by applying a quote. But to answer your question:
Code: Select all
htmlspecialchars($yourstring, ENT_QUOTES);-
polishvalor
- Forum Newbie
- Posts: 13
- Joined: Sat Nov 06, 2010 10:45 pm
Re: include a .txt file
Code: Select all
htmlspecialchars($yourstring, ENT_QUOTES);and how would this look like with an include()?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: include a .txt file
and how would this look like with an include()?[/quote]polishvalor wrote:Code: Select all
htmlspecialchars($yourstring, ENT_QUOTES);
Why are you using an include()? Why not use a function that will return the string instead. I.e., file_get_contents(), or file(), or fopen() + fgets() + fclose()
If you are insistent on using an include(), then you need to out output buffering to capture the output. I.e.,
Code: Select all
ob_start();
include($yourTextFile);
$ret = ob_get_contents();
ob_end_clean();