473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem echoing \r\n


If I set a varaible as

$EOL = "\r\n"

But then want to echo that to a HTML page to see the above string
i.e. \r\n

by doing: echo($EOL);

How do I do it?

I've tried quotemeta, addslashes and htmlspecialchar
but can't seem to work it out.

thanks

Andy
Apr 2 '07 #1
11 9265
an****@blueyonder.com schrieb:
If I set a varaible as

$EOL = "\r\n"

But then want to echo that to a HTML page to see the above string
i.e. \r\n

by doing: echo($EOL);

How do I do it?

I've tried quotemeta, addslashes and htmlspecialchar
but can't seem to work it out.

thanks

Andy
It should work with single quotes:
$EOL = '\r\n';
echo $EOL;

That should output:
\r\n
Apr 2 '07 #2
On Apr 2, 2:08 pm, Mike Roetgers <miker...@informatik.uni-bremen.de>
wrote:
and...@blueyonder.com schrieb:
If I set a varaible as
$EOL = "\r\n"
But then want to echo that to a HTML page to see the above string
i.e. \r\n
by doing: echo($EOL);
How do I do it?
I've tried quotemeta, addslashes and htmlspecialchar
but can't seem to work it out.
thanks
Andy

It should work with single quotes:
$EOL = '\r\n';
echo $EOL;

That should output:
\r\n
and, of course, it should (and does) work as you've described - with
the combination of addslashes and htmlspecialchars, although it will
work fine with just addslashes, but it isn't formally correct. So you
should do echo htmlspecialchars(addslashes("\r\n"));

Apr 2 '07 #3
andy.z wrote:
If I set a varaible as

$EOL = "\r\n"

But then want to echo that to a HTML page to see the above string
i.e. \r\n

by doing: echo($EOL);
Do you mean that you want the page to have the exact string:

backslash, r, backslash, n

??

If so, then use 'single quotes' when setting $EOL, not "double quotes".

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 2 '07 #4
In article <11**********************@e65g2000hsc.googlegroups .com>,
da**************@gmail.com says...
and, of course, it should (and does) work as you've described - with
the combination of addslashes and htmlspecialchars, although it will
work fine with just addslashes, but it isn't formally correct. So you
should do echo htmlspecialchars(addslashes("\r\n"));
Not what I'm asking Darko.

Andy
Apr 2 '07 #5
In article <eu**********@kohl.informatik.uni-bremen.de>,
mi******@informatik.uni-bremen.de says...
>
It should work with single quotes:
$EOL = '\r\n';
echo $EOL;

That should output:
\r\n
Yes but it's no use to me with single quotes.
The variable is set with double quotes.

$EOL = "\r\n"

I want to echo that variable AS IF - it had been set with single quotes.

Andy
Apr 2 '07 #6
In article <hr************@ophelia.g5n.co.uk>,
us**********@tobyinkster.co.uk says...
andy.z wrote:
If I set a varaible as

$EOL = "\r\n"

But then want to echo that to a HTML page to see the above string
i.e. \r\n

by doing: echo($EOL);

Do you mean that you want the page to have the exact string:

backslash, r, backslash, n

??

If so, then use 'single quotes' when setting $EOL, not "double quotes".

As shown above in the example I gave - the variable is set with double
quotes.
I want to echo it as a string.

Andy
Apr 2 '07 #7
andy.z wrote:
I want to echo that variable AS IF - it had been set with single quotes.
In the general case, there's no way of doing that -- double-quoted strings
are interpolated and unescaped as soon as they are encountered, and after
that there's no way of going back to the original string.

However, in this specific case, addcslashes() should do the trick.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 2 '07 #8
an****@blueyonder.com kirjoitti:
If I set a varaible as

$EOL = "\r\n"

But then want to echo that to a HTML page to see the above string
i.e. \r\n

by doing: echo($EOL);

How do I do it?

I've tried quotemeta, addslashes and htmlspecialchar
but can't seem to work it out.

thanks

Andy
$EOL = "\\r\\n";

--
Ra*********@gmail.com
"Olemme apinoiden planeetalla."
Apr 2 '07 #9
In article <o9************@ophelia.g5n.co.uk>,
us**********@tobyinkster.co.uk says...
>
In the general case, there's no way of doing that -- double-quoted strings
are interpolated and unescaped as soon as they are encountered, and after
that there's no way of going back to the original string.

However, in this specific case, addcslashes() should do the trick.

Nice - I missed that one in the documentation - that tiny 'c' was
probably too small for my eyes to see (bad eyesight)

Its a very interesting function anyway.
Thanks Toby I'll give that a go.

Andy.
Apr 2 '07 #10
In article <eu**********@nyytiset.pp.htv.fi>, ra*********@gmail.com
says...
$EOL = "\\r\\n";
No.
Apr 2 '07 #11
On Apr 2, 9:07 am, and...@blueyonder.com wrote:
In article <eur7vm$6u...@nyytiset.pp.htv.fi>, rami.elo...@gmail.com
says...
$EOL = "\\r\\n";

No.
Whaddya mean, "No." ?

Are you trying to say you can't control how the $EOL variable is set -
you want a function to take "\r\n" and turn it into somoe output that
shows as \r\n in a browser? If so, you'll have to write a function.

Apr 2 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: throat.wobbler.mangrove | last post by:
Hi, I was hoping someone may be able to help me with a tricky T-SQL problem. I need to come up with a SELECT statement that does basically the following: Select RCRD_REFNO, MAX(MODIF_DTTM)...
2
by: Alex Prentki | last post by:
Hi guys, i have the following TABLE: FIELD1 FIELD2 FIELD3 1 A 23 1 B 77 <<< i want to select this row 2 C 12 2 D 99 <<< and this one 2 E 17 3 ...
1
by: Nicole | last post by:
I have this query: SELECT AGG_NAME, MAX(AGG_RELNUM) RELNUM, MAX(AGG_RELSPEC) RELSPEC, MAX(ED) EDIZ FROM (SELECT ..... ) AT GROUP BY AGG_NAME The problem that the query reply records in...
3
by: Mark Szlazak | last post by:
The following page simulates a pool cue and cue ball: http://members.aol.com/myscript/cue.html Mouse cursor position around the cue ball determines where a roll-over of 179 pool cue images is...
11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
12
by: Felix85 | last post by:
here is my method for reading in a file: static room room::file2Room(int rnum){ ostringstream filename; filename << "../gamefiles/rooms/" << rnum << ".room"; ifstream...
2
by: JoeC | last post by:
I have kinda complex question. I am writing a game program and I am trying to derrive things from my graphic library. For starters I want to derrive the terrain from my graphics so that I can...
3
by: vorange | last post by:
Hello, I have a problem I have been unable to solve for quite some time now. I'm using the Serialport class and opening the port and writing a byte to it. The byte is successfully received by...
4
by: Heron | last post by:
Hi, Could someone explain me why the following code doesn't work? The memorystream always remains with length 0. MemoryStream input = new MemoryStream();
4
by: JovieUrbano | last post by:
I have a question. I am working on something based on the information I got from this forum. I am using the sample I found and modifying it a little to get the results I want.. --TABLE--...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.