Escape char handling in arguments

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Escape char handling in arguments

Post 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...
Last edited by Shendemiar on Mon Oct 06, 2008 8:54 am, edited 1 time in total.
PietM
Forum Newbie
Posts: 8
Joined: Mon Oct 06, 2008 2:56 am

Re: Escape char handling in arguments

Post 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.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Re: Escape char handling in arguments

Post by Shendemiar »

Ok, Thanks. I can live with that.
Post Reply