使用PHP附加标签 [英] Append tags using PHP

查看:88
本文介绍了使用PHP附加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PHP动态添加列表项。但是下面的代码什么也没做。

据我所知,每次刷新页面时,都应该创建并显示一个新的列表项。但这不会发生。



我尝试过:



<!DOCTYPE html>

< html>

< head>

< title>< / title>

< / head>

< body>



< ul id =test>

< li>样本< / li>

<?php

$ html = file_get_contents('index.php');

$ doc = new DOMDocument();

$ doc - > loadHTML($ html);



$ ul = $ doc - > getElementById('test');

$ li = $ doc - > createElement('li','Test');

$ ul - > appendChild($ li);

?>

< / ul>



< / body> ;

< / html>

解决方案

html = file_get_contents('index.php');


doc = new DOMDocument();


doc - > loadHTML(

I want to add list items dynamically using PHP. But the code below does nothing.
According to me, everytime I refresh the page, a new list item should be created and displayed. But this isn't happening.

What I have tried:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<ul id="test">
<li>Sample</li>
<?php
$html = file_get_contents('index.php');
$doc = new DOMDocument();
$doc -> loadHTML($html);

$ul = $doc -> getElementById('test');
$li = $doc -> createElement('li', 'Test');
$ul -> appendChild($li);
?>
</ul>

</body>
</html>

解决方案

html = file_get_contents('index.php');


doc = new DOMDocument();


doc -> loadHTML(


这篇关于使用PHP附加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆