duanche9384 2015-03-07 11: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 11: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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了