duanche9384 2015-03-07 19:04
浏览 32
已采纳

在dom php中加载文件时出错

I am using the below code to create a div <-- successfully. The problem is when i try to create a child div and select $pagenameselected.php to load. Here I get an error because when it loads $pagenameselected <-- it load the php script to create the div and not the created div like i can see in page source.

 <?php
 $myfile = fopen("../userfolders/$email/$ongrassdb/$pagenameselected.php", "w") or die("Unable to open file!");
 $x = "<?php " . '$dom' . "= new DOMDocument();" .
 '$element' . "= " . '$dom' . "->createElement('div', '$textcon');" .
 '$dom' . "->appendChild(" . '$element' . ");
 echo " . '$dom' . "->saveXML();?>";
 fwrite($myfile,$x);
 fclose($myfile);
 ?>

 $myfile = fopen("../userfolders/$email/$ongrassdb/$pagenameselected.php", "w") or die("Unable to open file!");
 $file = $DOCUMENT_ROOT. "../userfolders/$email/$ongrassdb/$pagenameselected.php";
 $doc = new DOMDocument();
 $doc->loadHTMLFile($file);
 //$elements = $doc->getElementsByTagName('div');
  • 写回答

1条回答 默认 最新

  • doushi4864 2015-03-07 19:11
    关注

    The class is expecting an HTML document, you are sending it a PHP document.

    instead of using the $x =

    You should just do this ...

    $dom = new DOMDocument();
    $ele = $dom->createElement('div', $textcon);
    $dom->appendChild($ele);
    $html = $dom->saveXML();
    
    fwrite($myfile, $html);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效