3

I've seen a thread relating to altering conditional comments, but I can't find whether it's possible to add new conditional comments using the php dom functionality.

I essentially want to be able to add the following into (not the only example, but you get the idea!).

<!--[if ! lte IE 6]><link rel="stylesheet" href="css/default.css" /><!--<![endif]-->

I've looked at DomComment but it seems to add the closing tag for the comment, so I end up with:

<!--[if ! lte IE 6]--><link rel="stylesheet" href="css/default.css" /><!--<![endif]-->

1 Answer 1

3

this:

<?php
$doc = new DOMDocument();
$doc->loadHTML("<html><body><p id='bla'>Test</body></html>");
$bla = $doc->getElementById("bla");
$bla->appendChild(new DOMComment('[if ! lte IE 6]><link rel="stylesheet" href="css/default.css" /><![endif]'));

echo $doc->saveHTML();  //<!--[if ! lte IE 6]><link rel="stylesheet" href="css/default.css" /><![endif]-->

works for me. note that the proper syntax for a conditional comment is

<!--[if ! lte IE 6]><link rel="stylesheet" href="css/default.css" /><![endif]-->

not

<!--[if ! lte IE 6]><link rel="stylesheet" href="css/default.css" /><!--<![endif]-->

as you say you want to have it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.