1
I have for example this code that removes all DIVs
containing the class contextual
of my code HTML
passed in string $sHTML
:
$nPosIni = strpos($sHTML, '<div class="contextual">');
while ($nPosIni > 0) { // remove todas as divs com a classe contextual
$nPosFim = strpos($sHTML, '</div>', $nPosIni);
$sHTML = substr($sHTML, 0, $nPosIni) .
substr($sHTML, ($nPosFim + strlen("</div>")));
$nPosIni = strpos($sHTML, '<div class="contextual">');
}
So what I need is to remove from a code HTML
another <div>
with another class, but I want only one <h3> CONTEÚDO </h3>
that’s inside that <div>
.
I tried in many ways but I couldn’t find an efficient way, someone knows some good practice?
OBS.: The code I am using does not accept scripts or functions, only PHP
, HTML
and CSS
...
SAMPLE HTML:
<html>
<head></head>
<body>
<div class="xy">
<h3> conteúdo </h3>
</div>
</body>
</html>
HTML AS IT SHOULD BE:
<html>
<head></head>
<body>
<h3> conteúdo </h3>
</body>
</html>
Already tried something with the Domdocument class?
– Woss
You can provide copy of the html code that serves as the basis for this routine?
– Caiuby Freitas
Do you want the div to remain if you have the H3? Or remove the div and keep the H3 element inside?
– Diego Schmidt
@Andersoncarloswoss, I didn’t try, as you suggest?
– Marcos Henzel
@Diegoschmidt, I want to remove all DIV and leave only the H3 inside.
– Marcos Henzel
@Caiubyfreitas, I believe that the code is not necessary, because it would serve for any type of code ...
– Marcos Henzel
You can put an example in the HTML code question, how it is and how it should look?
– Woss
Sure, just a moment...
– Marcos Henzel
Updated question, it is very direct even, I put only one example of the use I need.
– Marcos Henzel