Ramalingam Perumal
Ramalingam Perumal

Reputation: 1427

PHP Simple HTML DOM - How to get the text inside a tag

I use PHP Simple HTML Dom to get some HTML, now I have a HTML dom like follow code, I need fetch the plain text inner a tag, but I am getting the text link(Kiwi Fruit Basket).

HTML Code

<div class="name" style="height: 34px;">
    <a href="http://floristchennai.com/kiwi-basket">Kiwi Fruit Basket</a>
</div>

Php Code

 // Create DOM from URL or file
 $html = file_get_html('http://floristchennai.com/');

 // Find all links text
 foreach($html->find('.name a') as $element) 
 {
    echo "<br>a tag text value=" . $element;
 }

Doing it this way I don't get the text I want to get.

Thanks in advance!

Upvotes: 0

Views: 5229

Answers (1)

Awlad Liton
Awlad Liton

Reputation: 9351

try: innertext() innertext used for Read or write the inner HTML text of element.

    foreach($html->find('.name a') as $element) 
    {
        echo "<br>a tag text value=" . $element->innertext;
    }

API Ref

Upvotes: 4

Related Questions