Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie: odd escape problem

Status
Not open for further replies.

rantnrave

Programmer
Jul 21, 2002
11
0
0
GB
I have PHP4 with apache 1.3.27 on Win2k.
I have been unable to get escaped characters to work properly. Specifically, \n \r and \t just add a space, while \" \$ and \\ work fine.
For example:
Code:
print "Top\nBottom";
gives:
Top Bottom
(
Code:
echo
gives the same result.)
Any idea what's going on? Seems a very silly problem. It must be me...
 
This is the way browsers interpret HTML files. All space characters are turned into one space. If you want to see the results of \t and \r\n, you would have to view source or have your program output in text/plain mode, by sending a content-type header to the browser. //Daniel
 
Alternatively, you can bracket that output in &quot;<PRE>...</PRE>&quot; tags. ______________________________________________________________________
TANSTAAFL!
 
Aha! That works. Think I need an HTML refresher.
Thanks.
 
Is this a common problem? None of the books mention the possibility of escaping not working, yet I'm not doing anything they don't all suggest as a first program. Although the <pre> solution works, I'm interested in a more permanent solution.
What would a content-type header look like? Perhaps it's covered in an HTML or PHP book.
 
The escaping is working, it's just that you can't see it with a browser. If you view the source, all your escaped characters will be there. If you are thinking about changing the content-type, you're script will no longer output HTML pages, just text files. I'm guessing that this isn't what you want, but here is how you would change it anyway:
Code:
header('Content-type: text/plain');
You need that line of PHP before you output anything, preferably the very first line of your script. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top