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.)
Asked
Active
Viewed 108 times
2

Loko
- 6,539
- 14
- 50
- 78
4 Answers
2
Use a Regular Expression
to simplify things. Pass your XML
content like shown.
$filtered_content = preg_replace("/<img[^>]+\>/i", "(image) ", $your_xml_content);

Shankar Narayana Damodaran
- 68,075
- 43
- 96
- 126
-
1This did work thanks. Could use some more explaining for the people visiting later like: $xmltoecho = preg_replace("/
]+\>/i", "(image) ", $your_xml_content); How to use preg_replace: preg_replace("What to replace","What replaces it",$your_xml_content); Thanks anyway! – Loko Sep 24 '13 at 12:47
2
you can use a regular expression to replace the image tag......or just using the style property you can make the visibility of the image tag to hidden or display to none as it gets loaded.

Let me see
- 5,063
- 9
- 34
- 47
-2
If you have a DOMDocument, you can getElementsByTagname then iterate through the list you get to removeChildren. Removing attributes won't do it.

kubi
- 829
- 2
- 14
- 24
-
If you clicked the link I provided, You could see I want it different than this way. – Loko Sep 24 '13 at 12:46
-
Well, I did click the link (what's with the assumption!), and my solution _is_ different than "this way", as it would actually work (removeChild is "good for this problem" while removeAttribute is not). You could've clarified what exactly is wrong with "that way", before downvoting a correct solution. – kubi Sep 24 '13 at 22:20
-
It's still an even bigger and annoying solution. + you're telling , removing attributes wont do it. Which I just did. – Loko Sep 25 '13 at 06:35