Forum Moderators: coopster

Message Too Old, No Replies

Validator Error

need help with escaping special characters

         

m8fyu

7:16 pm on Jun 26, 2009 (gmt 0)

10+ Year Member



Validator tells me

Many Document Types based on XML need a mandatory xmlns="" on the root element. For example, the root element for XHTML will look like:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

This line is contained inside my php script so the double forward slashes are causing the rest of the line to appear as a comment

Please can someone explain how I can stop this? I'm very new to PHP and working with code that's already written. I've managed to do most other things that I want but this has had me stumped for a while now.

I've read about escaping special characters and attempted to do this using a backslash after the semi-colon but it doesn't work.

any help is much appreciated.

The code I am working with reads:
$str .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
$str .= "<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">";

g1smd

7:19 pm on Jun 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you escape " using \" then you'll escape / by using \/ here.

I much prefer to use 'single quotes' around text like that, then the problem never arises.

m8fyu

8:15 pm on Jun 26, 2009 (gmt 0)

10+ Year Member



thanks
Thanks. I'm using \" but it isn't working for me. my code is as follows. when i preview in the browser i simply get a blank screen. yet if i simply have <html> and omit the rest of the line it works perfectly - yet doesn't validate. i tried using /" too but with no joy.

$str .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
$str .= "<html xmlns="http:\"//www.w3.org/1999/xhtml" xml:lang="en" lang="en">\"";

andrewsmd

9:25 pm on Jun 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about this

$str .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
$str .= "\n";
$str .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';

m8fyu

9:48 pm on Jun 26, 2009 (gmt 0)

10+ Year Member



thanks so much. works a treat.

g1smd

10:09 pm on Jun 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That was the 'single quotes' solution I mentioned above. :)

m8fyu

10:26 pm on Jun 26, 2009 (gmt 0)

10+ Year Member



thanks also g1smd. i thought it must have been what you were telling me. i just couldn't figure it out without someone literally spelling it out for me. one day i will have this php thing licked - but not today!