Gui*_*ser 0 html php select class
我目前正在一个网站上工作.我需要使用PHP来选择具有某个类的div.例如:
<body>
<div class="header"></div>
<div class="other-class"></div>
<div class="one-two-three"></div>
<div class="footer"></div>
</body>
<?php
if(div.hasClass('one-two-three'))
{
//function code here...
}
?>
Run Code Online (Sandbox Code Playgroud)
但请记住,我想使用PHP而不是jQuery ...
如果你想操作DOM,在将它发送到客户端之前,那么Dom对象就是你需要的东西.它甚至有类似于你可能已经从JS知道的方法.
$htmlString = '<html>...</html>';//either generated, or loaded from a file
$dom = new DOMDocument;
$dom->loadHTML($htmlString);//or loadHTMLFile
$divs = $dom->getElementsByTagName('div');
foreach($divs as $div)
{
if ($div->hasAttribute('class') && strstr($div->getAttribute('class'), 'one-two-three'))
{
//$div ~= <div class='one-two-three'>
$div->appendChild();//check the docs to see what you can do
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12633 次 |
最近记录: |