468,249 Members | 1,488 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

tricky /n

is /n counted as one character or two?
ie I want to cut any line breaks from the begining of a message
should it be
while(substr($message,0,1)=="\n") $message=substr($message,1);
or
while(substr($message,0,3)=="\n") $message=substr($message,2);

???
Jul 17 '05 #1
3 1446
On Mon, 25 Oct 2004 13:24:00 +0100, brendan
<br*************@srl.cam.ac.uk_nospam> wrote:
is /n counted as one character or two?
"/n" is two.
'/n' is two.
'\n' is two.
"\n" is ONE - a newline character.
ie I want to cut any line breaks from the begining of a message
should it be
while(substr($message,0,1)=="\n") $message=substr($message,1);
or
while(substr($message,0,3)=="\n") $message=substr($message,2);


As a further complication, the end of line in Windows /is/ two characters -
"\r\n". Whereas on Unix, it's one, "\n". (I think on Macs it is just "\r").

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
.oO(brendan)
is /n counted as one character or two?
Depends.
ie I want to cut any line breaks from the begining of a message
should it be
while(substr($message,0,1)=="\n") $message=substr($message,1);
or
while(substr($message,0,3)=="\n") $message=substr($message,2);


trim() exists.

Micha
Jul 17 '05 #3
brendan wrote:
is /n counted as one character or two?
two characters, no matter how you delimit it

"/n" == '/n'
However, with a backslash instead, it is different:

strlen("\n") == 1
strlen('\n') == 2
ie I want to cut any line breaks from the begining of a message
should it be
while(substr($message,0,1)=="\n") $message=substr($message,1);
or
while(substr($message,0,3)=="\n") $message=substr($message,2);

???


Neither. use ltrim()

http://www.php.net/ltrim
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Lars Plessmann | last post: by
reply views Thread by dracolytch | last post: by
1 post views Thread by JZ | last post: by
4 posts views Thread by Angel Cat | last post: by
25 posts views Thread by PyPK | last post: by
5 posts views Thread by Danny | last post: by
8 posts views Thread by pras.vaidya | last post: by
7 posts views Thread by NileshKorpe | last post: by
1 post views Thread by MorrganMail | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.