Page 1 of 1

Escape char handling in arguments

Posted: Mon Oct 06, 2008 8:32 am
by Shendemiar
Ok, example:

Code: Select all

 
  function xml()    { return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n"; }
  function doctype(){ return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> \n'; }
 
With the above, echoed to document, the linefeed, \n, works fine, but its pain in the ass to escape all the "'s in the string. And the one below, while more convenient, does not insert the linefeed to the document.

Why is this and what and where I could read about it. Googleing for single or double quote, escapes, leads me to nowhere...

Re: Escape char handling in arguments

Posted: Mon Oct 06, 2008 8:34 am
by PietM
*edit: I = stupid

You should use this, I think:

Code: Select all

 
function doctype(){ return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' . "\n"; }
 
\n should always be between ""-quotes.

Re: Escape char handling in arguments

Posted: Mon Oct 06, 2008 8:52 am
by Shendemiar
Ok, Thanks. I can live with that.