简体   繁体   中英

PHP exclude information from xml

I want to exclude just the <img> tag(ads in a newsfeed) from an xml file to be shown at my php file. I know that these should work to remove attributes but isn't there anything else to just remove the img from being shown? I think there has to be another way for this and would like to know what php function is good for this problem? (+ the information in the link doesn't work for me.)

Use a Regular Expression to simplify things. Pass your XML content like shown.

$filtered_content = preg_replace("/<img[^>]+\>/i", "(image) ", $your_xml_content);

您可以使用正则表达式替换image标签……或仅使用style属性就可以使image标签的可见性隐藏起来,或者在加载时不显示。

Maybe this stack overflow question can be of help. Putting your xml in the $content string and regexing just as described in the top answer.

If you have a DOMDocument, you can getElementsByTagname then iterate through the list you get to removeChild ren. Removing attributes won't do it.

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