Re: Curious

From: Date: Wed, 28 Mar 2001 06:48:18 +0000
Subject: Re: Curious
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-45838@lists.php.net to get a copy of this message
> >I am curious to know why you need to use the /n, and what it actually does, > >because I had a page that used them, and i removed them all and it still > >works fine. > > As far as the HTML output, it wont affect how it shows up on the screen, > but if you look at the HTML code, you will notice everything is on 1 > big-ass long line. > > Using a /n at the end of an echo or print statement will put a carriage > return at the end so your HTML code is more pleasant to view and makes it > alot easier to view when you are trying to work out any problems in HTML > layouts. Umm, it's a newline, and it should be used as \n (not /n). It's a C style escape for the new-line character. I beleive using \r will insert a carrige-return. Anyway, same sort of difference (depending on the editor).. puts the following text on the next line... NOTE: *nix text files just use a Newline at the end of each line. DOS (windows) files use a \r\n pair at the end of each line (Carrige-return, line feed). To make sense of this, think of a type writer or an old dot-matrix printer.. carrige return: you've moved the print head back to the left.. newline/linefeed, rolled through one line. > >Also, is it seen as good or bad practive to use \" only when required or all > >the time. > > My general rule of thumb is to use \" whenever I need a " > > in general, I avoid using quotes where possible (such as in the following) > <font size=3 face=Arial> (instead of <font size=\"3\" > face=\"Arial\">) > > But for things like ALT tags, I use \" because spaces are required in the > value of the ALT tag. Lets show an example: echo "This is a string"; would print out: This is a string however: echo "This is a "string""; would spit out a pasing error. The quoted string (") ends at: This is a however, 'string' and the following "'s would not encasing anything. Rule of thumb: If you are using double quotes to enclose a string, but you want double quotes within as well, use \" (called escaping). Same goes for the $ symbol. within quotes, if you want the symbol to show up, use \$. Otherwise, it'd try to evaluate it as variable! This is all documented err, somewhere *digs though manuals*, but strangely enough I can't find it :-| hope this helps. bkx

« previous php.general (#45838) next »