Question

I am using PHP Simple HTML DOM Parser * [Manual] to fetch data from websites.

Now what I wanna do is to remove first three words from all span which has class="yeah" from the fetched content. So I have implement this code but it has a problem:

foreach($html->find('span.yeah') as $xdat)
{
    $x_des = implode(' ', array_slice(explode(' ', strip_tags($xdat)), 0, 3));
    $result = str_replace($x_des, ' ', $result);
    $result = str_get_html($result);
}

Though it delete first three words from all <span class="yeah"> but the problem is, this modify full fetched content. But I wanna modify only those data whose are in <span class="yeah"> but it match first three words from all fetched data and then delete all of them, though I wanna remove those data from only those span types.

Asumming fetched data is:

Some first three words content <span class="yeah">first three words some content some content</span> continue to some content

So, the output should be:

Some first three words content <span class="yeah"> some content some content</span> continue to some content

Here, "first three words" was the first 3 words of that span type so I need to remove it from the span type only instead of being deleted from the full content.

So, how to remove only first three words from all <span class="yeah"> </span> in the fetched content?

No correct solution

OTHER TIPS

foreach($html->find('span.yeah') as $xdat)
{
    $result = strip_tags($xdat);
    $result = str_get_html($result);
}

it will strip all the html tags and attributes though including span and class="yeah".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top