LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-16-2006, 08:55 AM   #1
deadlock
Member
 
Registered: Apr 2003
Distribution: Red Hat
Posts: 65

Rep: Reputation: 15
Question PHP Escape Chararacters ignored


I'm having problems with escape characters in double quoted strings.

Basically my PHP install (or perhaps just firefox?) is ignoring escape commands, so "\n", "\r", etc are being ignored. However "\\" is interpreted as a single "\".

The example script I am tring to run is as follows:

PHP Code:
<?php
    printf
("pi equals %f\n"3.14159);
    
printf("%.2f\n"3.14159);
    
printf("%10.2f\n"3.14159);
    
printf("%.10f\n"3.14159);
    
printf("%.9s\n""halfofthestring");
    
printf("%b %d %f %s\n"123123123"test");
?>
So each of the printf() instances should be on a new line, but are instead run on into each other.

Any Help
 
Old 01-16-2006, 09:03 AM   #2
deadlock
Member
 
Registered: Apr 2003
Distribution: Red Hat
Posts: 65

Original Poster
Rep: Reputation: 15
I think I've worked it out actually - I wasn't putting <Pre> tags around the PHP block...

Would this be the reason?
 
Old 01-16-2006, 09:04 AM   #3
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
If you need to print a new line, you need to use <br /> because "\n" only affects the source of the html page and not the actual html that php produces. The code below is a sample of what you would need to do
Code:
<?php
    printf("pi equals %f\n<br />", 3.14159);
    printf("%.2f\n<br />", 3.14159);
    printf("%10.2f\n<br />", 3.14159);
?>
 
Old 01-16-2006, 10:25 AM   #4
YissKill
LQ Newbie
 
Registered: Mar 2005
Distribution: Debian (Woody & Sarge), Kubuntu, Suse, Linuxin, Peanut
Posts: 5

Rep: Reputation: 0
actually you could do it by two diferent ways you can add a print "<pre >" line or add the <br > tag before the "\n" cause the normal jumps of line are usually ignored by the browser till you specify the browser to respect the format with the <pre > tags so you worked it out fine, but if you don't want to mess with style tags and use the conventional text format tags <font >, <b > and so on you can use the <br > tag to insert the line jump.

Regards JIG
 
Old 01-16-2006, 10:38 AM   #5
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Quote:
Originally Posted by YissKill
actually you could do it by two diferent ways you can add a print "<pre >" line or add the <br > tag before the "\n" cause the normal jumps of line are usually ignored by the browser till you specify the browser to respect the format with the <pre > tags so you worked it out fine, but if you don't want to mess with style tags and use the conventional text format tags <font >, <b > and so on you can use the <br > tag to insert the line jump.

Regards JIG
You can put <br /> before or after \n, its just a matter of preference. I like <br /> on its own line when reading the source, so I tend to put it after \n or in a seperate print statement. It really doesn't make a difference to the resulting php program, so use it whichever way is best for you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i escape a / ??? Fascistchicken Linux - General 10 09-12-2004 11:28 AM
Escape character ? juanb Linux - Newbie 2 08-31-2004 10:03 AM
Escape! Wind0wR3fuge Linux - Newbie 6 07-11-2004 03:00 AM
escape sequence help in C name_in_use450 Linux - General 6 07-01-2004 09:23 AM
disable escape def1014 Linux - Security 1 04-16-2002 04:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration