检查div ID是否存在(PHP) [英] Check if div ID exists (PHP)
本文介绍了检查div ID是否存在(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PHP是否可以检查元素是否存在?
Is it possible to check if an element exists with PHP?
我已经知道javascript方法,但我只想尽可能避免使用它。 / p>
I'm aware of the javascript method already but I just want to avoid it if possible.
推荐答案
如果字符串中包含HTML服务器端,则可以使用 DOMDocument :
If you have the HTML server side in a string, you can use DOMDocument:
<?php
$html = '<html><body><div id="first"></div><div id="second"></div></body></html>';
$dom = new DOMDocument;
$dom->loadHTML($html);
$element = $dom->getElementById('second');
// this will be null if it isn't found
var_dump($element);
这篇关于检查div ID是否存在(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文