JustinK101 Posted April 22, 2008 Share Posted April 22, 2008 I have a file called html_doctype.inc which I am trying to require_once(). The file html_doctype.inc looks like: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> I am simply calling require_once("html_doctype.inc"); The problem is that php thinks the first line, the xml version and encoding tag is an opening php tag and tries to parse that text. How can I get around this error? Link to comment https://forums.phpfreaks.com/topic/102286-cant-require-doctype-file-with-xhtml/ Share on other sites More sharing options...
thebadbad Posted April 22, 2008 Share Posted April 22, 2008 If you include PHP in the file, you could use heredoc syntax, or echo the "<?" and "?>": <?php $str = <<<DOC <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> DOC; echo $str; ?> or <?php echo '<?'; ?>xml version="1.0" encoding="utf-8"<?php echo '?>'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> Link to comment https://forums.phpfreaks.com/topic/102286-cant-require-doctype-file-with-xhtml/#findComment-523763 Share on other sites More sharing options...
thebadbad Posted April 22, 2008 Share Posted April 22, 2008 Or simply just wrap the string in single quotes. Dunno why I thought you needed the heredoc syntax. Link to comment https://forums.phpfreaks.com/topic/102286-cant-require-doctype-file-with-xhtml/#findComment-523767 Share on other sites More sharing options...
JustinK101 Posted April 22, 2008 Author Share Posted April 22, 2008 Thanks, I like this method: <?php echo '<?'; ?>xml version="1.0" encoding="utf-8"<?php echo '?>'; ?> Link to comment https://forums.phpfreaks.com/topic/102286-cant-require-doctype-file-with-xhtml/#findComment-523771 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.