I have html code in which are many divs, and want delete some divs from this code, it's so hard to do with substr()
or similar php string function, maybe are better way to do this ?
strip_tags() might be of help:
http://php.net/manual/en/function.strip-tags.php
You can do this with javascript. Just give the divs unique id's, then you can write some simple javascript like so.
document.getElementById('divid').remove();
Note: Make sure the element(s) have loaded before running the remove(). - You can do this with jquery.
$(document).ready(function(){
document.getElementById('divid').remove();
});
Alertnativly, if you decide to add elements maybe some time after the document has loaded, then remove them, you can check to see if an element exists with the following code. (again using the jquery library), could can also use css selectors with an object, being as you're using jquery.
if ($("#divid").length > 0){
$('#divid').remove();
}
That code can become handy, if say - You gradually add elements into the document, with like a live-comment system, you could use setInterval(), to keep checking if the element exists, and when it does, remove it.
If you NEED to do this with php then Brian Agnew's answer of using the PHP HTML parser should solve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With