Get the inner text using curl concept in php

前端 未结 5 1530
情深已故
情深已故 2021-01-25 15:18

This is html text in the website, i want to grab

1,000 Places To See Before You Die

5条回答
  •  执念已碎
    2021-01-25 15:37

    There are 2 ways that I could think of to solve this. One, is that you grab the title attribute from the anchor tag. Of course, not everyone set up a title attribute for the anchor tag and the value of the attribute could be different if they want to fill it that way. The other solution is that, you get the innertext attribute and then replace every child of the anchor tag with an empty value.

    So, either do this

    $e->title;
    

    or this

    $text = $e->innertext;
    foreach ($e->children() as $child)
    {
        $text = str_replace($child, '', $text);
    }
    

    Though, it might be a good idea to use DOMDocument instead for this.

提交回复
热议问题