使用PHPDOM在div中获取php标记

使用PHPDOM在div中获取php标记,php,dom,Php,Dom,我试图用php Dom get元素按id获取div中的值,当我尝试这样做时,我从div中获得的值是“games and new games Release”,而我根本没有得到php值和php标记,例如:getElementById($selected\u div); $existing_Data=$element->firstChild->nodeValue; 回声'; 回声'; 回显“文本内容”$现有的_数据; 回声'; //div_页脚内容 所有游戏 新游戏发布 从您展示的内容中,我们无法猜

我试图用php Dom get元素按id获取div中的值,当我尝试这样做时,我从div中获得的值是“games and new games Release”,而我根本没有得到php值和php标记,例如:<?php回应hellow世界,如下所示。我想获取变量$existing_Data中div的所有内容,包括<?php和

$selected_div = "div_footer";
$file = '../myfolder/22selected.php';
$file_get = file_get_contents($file);

/* // which one to use here ? i am getting a headache !
$file_entity = htmlentities($file_get);
$file_htmlcharac = htmlspecialchars($file_entity);
$file_strip = stripslashes($file_htmlcharac);
*/

$doc = new DOMdocument();
$doc->loadHTML($file_get);
$element = $doc->getElementById($selected_div);
$existing_Data = $element->firstChild->nodeValue;

echo '<table>';
echo '<form action= "existing_Data.php" method = "POST">';
echo 'Text Content <textarea rows="12" cols="60" name="content" id ="text_content">' . $existing_Data . '</textarea>';
echo '<input type ="submit" name = "submit" id = "submit" value = "Submit" ></form>';

// div_footer CONTENTS 
<div id = "div_footer">
<h1> All games</h1>
<p> new games releases</p>
<?php echo "hello world"; ?>
</div>
$selected\u div=“div\u footer”;
$file='../myfolder/22selected.php';
$file\u get=文件内容($file);
/*//这里使用哪一个?我头痛!
$file\u entity=htmlentities($file\u get);
$file\u htmlcharac=htmlspecialchars($file\u entity);
$file\u strip=stripslashes($file\u htmlcharac);
*/
$doc=新的DOMdocument();
$doc->loadHTML($file\u-get);
$element=$doc->getElementById($selected\u div);
$existing_Data=$element->firstChild->nodeValue;
回声';
回声';
回显“文本内容”$现有的_数据;
回声';
//div_页脚内容
所有游戏
新游戏发布


从您展示的内容中,我们无法猜测您想要实现的目标

当您使用
file\u get\u contents()
打开文件时,如果没有方案(http、ftp等),PHP会尝试通过本地文件系统打开文件,因此PHP不会解释标记。缺点是,它不是有效的XML/HTML,因此DOM解析器不会有帮助

您应该将数据写入数据库,或者至少写入XML、JSON或明文文件。要恢复该值,只需
$value=trim(file_get_contents('../mydata.txt')


另一种情况是,您希望(http-)发布该数据。那么也没有理由使用DOM解析器。只需将数据放入一个隐藏字段
您想做什么?尝试一下,更改
$file='../myfolder/22selected.php'
并添加您的http url
$file=http://yoursite.com/myfolder/22selected.php';
hey bro,建议已经完成了50%的工作,现在我可以看到php代码中的值,例如hello world,但我仍然看不到标记,例如<?php,我想从这里将$existing_data中的值转换为另一个表单,然后写入这里没有显示的值,因此$existing_data应该包含div_页脚的全部内容,如。。只是不是hello world,而是<?php echo hello world?><--tagsI只给了您一些提示,您自己就找到了解决方案,很聪明!