Slacks.
Slacks.

Reputation: 199

Just getting the title of a post with Simple_html_dom

Currently I am scraping a website which has this content displayed.

<h2 class="entry-title">
    <a href="http://www.example.com">Song Artist - Song Name</a>
</h2>

Now if I use the code provided below it will pull what's shown above but I want to get just the portion that is as the Song Artist - Song Name without the <a href=""></a> or <h2></h2> tags.

$html = file_get_html("http://www.example.com");
    foreach ($html->find('h2[class="entry-title"]') as $data)
{
    echo $data; 
};

Upvotes: 1

Views: 68

Answers (3)

Walid Gabteni
Walid Gabteni

Reputation: 1

@krishna Gupta

echo $data->innertext;

this will result with something like

<a href="http://www.example.com">Song Artist - Song Name</a> 

@Slacks

Just use

echo $data->plaintext;

Upvotes: 0

Krishna Gupta
Krishna Gupta

Reputation: 685

foreach ($html->find('h2[class="entry-title"] a') as $data)
{
    echo $data->innertext; 
};

Upvotes: 1

thelastshadow
thelastshadow

Reputation: 3644

After a bit of digging through their pretty ancient docs:

echo $data->children(0)->innertext

Should work.

Upvotes: 1

Related Questions