Picking Text from External Site URL

Asked

Viewed 59 times

0

I need to get the text between the tags of a website: <a href="">Este Texo</a>

I’m getting a hold of your href with this code:

        $dadosSite = file_get_contents($utl);
        $dom = new DOMDocument;
        @$dom->loadHTML($dadosSite);
        $links = $dom->getElementsByTagName('a');

        foreach ($links as $link)
        {
            $termo = 'video';
            $pattern = '/' . $termo . '/';
            if (preg_match($pattern, $link->getAttribute('href')))
            {
                echo $link->getAttribute('href');

            }
        }
  • 1

    Utilize $link->textContent; to capture the value of tag content.

  • @Valdeirpsr Ball show, perfect

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.