Remove div class and its content!

$string = '<div class="ow_googlemap_location_address">
                                España<span class="googlemap_pin ic_googlemap_pin"></span>
                            </div>';



$result = preg_replace('#<div class="ow_googlemap_location_address(.*?)</div>#', ' ', $string);

echo $result;

How to remove the entire div including the content insde?

$string = '';

Maybe?
Presuming there is never going to be anything else in the string.

My entire div looks like this:

<div class="bp-list-googlemap"><div class="ow_googlemap_location_view_presentation">
                            <div class="ow_googlemap_location_address">
                                21005 Huelva, España<span class="googlemap_pin ic_googlemap_pin"></span>
                            </div>
                            <div class="ow_googlemap_location_map" style="width:65%; display:none;">
                            </div>
							
							<div class="ow_googlemap_location_pareja">
							<a href="http://www.amigote.com/gente/huelva">huelva</a>, <a href="http://www.amigote.com/gente/espana">espana</a>
                            </div>
							
                         </div></div>

I want to remove this part from it:

<div class="ow_googlemap_location_address">
                                21005 Huelva, España<span class="googlemap_pin ic_googlemap_pin"></span>
                            </div>

21005 Huelva, España this is a dynamic part!

I use this:

$result = preg_replace('/<div class=\"ow_googlemap_location_address\">.*<\/div>/','',$string);

But it leaves 21005 Huelva, España

If all you want to achieve is to not let someone see certain content, you could use CSS for this if you don’t mind it showing up in the Page Source.

I need this as is on other pages! Only wan to remove on one page!

You could still apply using CSS to a single document. Or if you have a single PHP document that generates multiple results. You can simply check to see if the URL is appropriate and then apply the CSS rule to the right URL. Or do an if-else statement to remove the specific content you want. If you remove it like you are now, what difference does it make to not use CSS for not showing this particular content?

This works on one but doesn’t when there is more than one match:

/<div class="ow_googlemap_location_address">(.+?)<\/div>/s

This is one where I can’t help thinking that this may be the wrong approach to the problem: removing the content.
How is this string of html generated in the first place? Is it possible that snippet of code could be “not added” during creation based on a condition?

The content is stored in the PHP $map

I have to remove it from $map

$map = preg_replace('/<div class="ow_googlemap_location_address">(.+?)<\/div>/s','',$map);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.