Jump to content

Cant Require DocType File With XHTML


JustinK101

Recommended Posts

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

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">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.