简体   繁体   中英

Filter just one html tag with php

I have a php variable ( $string ) that contains a block of text (with html tags). What I want to do is filter just one tag: the <object></object> .

Haven't found any solution so far ...

You can use the DOMDocument::loadhtml to get the html from the $string you can use it like this :

<?php
    $DOM = new DOMDocument;
    //Parsing the string into html  
    @$DOM->loadHTML($string);
    //Getting all the elements with the <object> tag
    $objects = $DOM->getElementsByTagName("object");
?>

read more about the DOMDocument Class in here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM