This is a discussion on tricky /n within the PHP Language forums, part of the PHP Programming Forums category; is /n counted as one character or two? ie I want to cut any line breaks from the begining of ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
.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 |
|
|||
|
On Mon, 25 Oct 2004 13:24:00 +0100, brendan
<brendan_nospam_@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 / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |
|
|||
|
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. | |