开发者

What is the best way to get contents from a div?

开发者 https://www.devze.com 2023-03-20 22:59 出处:网络
I want to parse a dictionary and get contents from multiple divs with the same class, this is what I get from downloading the html:

I want to parse a dictionary and get contents from multiple divs with the same class, this is what I get from downloading the html:

this is the chosen word div:

<div class="box_palavra_escolhida"><img src="../img/icone-livro.png" width="41px" height="35px" border="0" alt="imagem icone livro"><a class="link_escolhida" href="dicsin_edicao.php?id=5166" title="a">a</a><a class="link_escolhida_sinonimo" href="dicsin_sinonimo_edicao.php?id=5166">Adicionar palavra</a></div>

from this div i want to get this:

<a class="link_escolhida" href="dicsin_edicao.php?id=5166" title="a">a</a>

then remove the tags and end up with: "a"

then get the synonyms to the word chosen, which are shown in this div:

<div class="palavras_encontradas"><div class="box_palavras_encontradas"><img src="../css/images/icone_livro_dois.jpg" width="23px" height="21px" border="0" alt="imagem icone livro dois"><a class="link_encontrada" href="dicsin_edicao.php?id=26716" title="insensato coração">(Antônimo) insensato coração</a><a class="link_encontrada_sinonimo" href="dicsin_lista.php?f_pesq=insensato coração">visualizar palavras</a></div><div class="box_palavras_encontradas"><img src="../css/images/icone_livr开发者_运维问答o_dois.jpg" width="23px" height="21px" border="0" alt="imagem icone livro dois"><a class="link_encontrada" href="dicsin_edicao.php?id=2081" title="anexar">(Sinônimo) anexar</a><a class="link_encontrada_sinonimo" href="dicsin_lista.php?f_pesq=anexar">visualizar palavras</a></div></div>

from this div I want to end up with:

<a class="link_encontrada" href="dicsin_edicao.php?id=2081" title="anexar">(Sinônimo) anexar</a>

and

<a class="link_encontrada" href="dicsin_edicao.php?id=26716" title="insensato coração">(Antônimo) insensato coração</a>

then after removing tags, end up with:

(Sinônimo) anexar

and

(Antônimo) insensato coração

can someone help me ? Thank you very much


The solution is simple, if you don't want any of the tags, then use strip_tags.

$content = strip_tags( $content );

In the first line, $content would be a, and so on.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号