wandersolo
wandersolo

Reputation: 69

get text inside single <br> tag simpleHTMLDOM PHP

I am trying to get text from an html file using the simplehtmldom lib for PHP. I only want the text after the <br> tag (TextAfterBreak) but only know how to get the entire text between the <font></font> tags (TextInsideFontTextAfterBreak in this case). I've tried find("/td/font/br") but it returns an empty string perhaps because there's no closing </br> tag? Any help would be greatly appreciated!

Here's the source html source file snippet:

<td>
    <font size="-1" face="Verdana, Helvetica, Arial, sans-serif" color="#330000">
    TextInsideFont
    <br>
    TextAfterBreak
    </font>
</td>

Here's my code snippet:

$element=$row->find("/td/font");
echo $element =$element[0]->plaintext;

And the output:

TextInsideFontTextAfterBreak

Note: Every table row in the html file is unique so any regex or string manipulators won't work.

Upvotes: 0

Views: 2427

Answers (1)

Mihai Iorga
Mihai Iorga

Reputation: 39724

explode() it after new line, because plaintext strips html data:

$element = $row->find("/td/font");
$element = explode("\n", $element[0]->plaintext);
echo trim($element[1]);

Upvotes: 3

Related Questions