PHP DomDocument更改条件注释 [英] PHP DomDocument alter conditional comments
本文介绍了PHP DomDocument更改条件注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< html xmlns =http://www.w3 .ORG / 1999 / XHTML>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8>
< link rel =stylesheettype =text / csshref =css / style.css>
< link rel =stylesheettype =text / csshref =css / elements.css>
< title>页面< / title>
<! - [if lte IE 6]>
< link rel =stylesheettype =text / csshref =css / ie6.css/>
<![endif] - >
< / head>
etc ...
我正在使用DomDocument库来修改< link>
属性。有没有办法让DomDocument读取和修改条件注释中的< link>
元素。
解决方案
foreach($ dom-> getElementsByTagName('head')as $ head){
foreach($ head-> childNodes as $ node){
if($ node instanceof DOMComment){
$ node-> replaceData(16,60,'test');
}
}
}
此代码工作,我只是让您搜索如何获取replaceData方法的'offset'和'count'值!
I have this html file with a conditional comment.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/elements.css">
<title>Page</title>
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="css/ie6.css" />
<![endif]-->
</head>
etc...
I am using the DomDocument library to modify the <link>
attributes. Is there any way of getting DomDocument to read and modify the <link>
element in the conditional comments.
解决方案
foreach($dom->getElementsByTagName('head') as $head) {
foreach($head->childNodes as $node) {
if($node instanceof DOMComment) {
$node->replaceData(16,60,'test');
}
}
}
This code works, I just let you search how to get 'offset' and 'count' value for the replaceData method !
这篇关于PHP DomDocument更改条件注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文