脚本宝典收集整理的这篇文章主要介绍了如何使用PHP将文本附加到特定标记内的外部html文件?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
例如:
<html> <body> <span class="text"></span> </body> </html>
我怎么用PHP做到这一点?我正在尝试为这个网站创建一个管理页面,我需要在某些标签内附加文本.我甚至不知道从哪里开始,请指出我正确的方向.
// Load the HTML document $doc = new DOMDocument; $doc->loadhtmlFile( 'htmlpage.html'); // Get the parent node where you want the insertion to occur $parent = $doc->getelementsbytagname('body')->ITem( 0); // Create the child element $child = $doc->createElement( 'span'); $child->setattribute( 'class','text'); // ApPEnd (insert) the child to the parent node $parent->appendChild( $child); // Save the resulting HTML echo $doc->savehtml();
所以,鉴于这个HTML:
<html> <body> </body> </html>
<html> <body> <span class="text"></span> </body> </html>
(如果DOMDocument不存在,则忽略DOMDocument添加的DOCTYPE声明)
以上是脚本宝典为你收集整理的如何使用PHP将文本附加到特定标记内的外部html文件?全部内容,希望文章能够帮你解决如何使用PHP将文本附加到特定标记内的外部html文件?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。