'Get Title from specific link - php

I am trying to get the title from an anilink url. This particular code works for MyAnimeList webiste however on the AniList website this keeps returning 'AniList' which is the website, i believe the website in question is updating the meta tags after loading the webpage using jquery, however sites like facebook and discord are able to get the title of a series. However my code can't.

here is the code i am using. For example, here is a random url from the anilist website

https://anilist.co/anime/527/Pocket-Monsters/

myfunction(https://anilist.co/anime/527/Pocket-Monsters/)

function myfunction($form_value)
{

$html = file_get_contents_curl($form_value);
 
       //parsing begins here:
         $doc = new DOMDocument();
         @$doc->loadHTML($html);
         $nodes = $doc->getElementsByTagName('title');
   
         //get and display what you need:
         $title = $nodes->item(0)->nodeValue;
        
         $metas = $doc->getElementsByTagName('meta');
         
        for ($i = 0; $i < $metas->length; $i++)
        {
            $meta = $metas->item($i);
            if($meta->getAttribute('property') == 'og:title')
               {$title = $meta->getAttribute('content');}
           if($meta->getAttribute('property') == 'og:site_name')
              $site_name = $meta->getAttribute('content');
       }


 return $title;
 
 }

andi it returns.

AniList 

where as this is the meta tag.

<meta property="og:title" content="Pokémon" data-vue-meta="true">

So i am expecting it to return

Pokémon

Should i be using another website to get the desired result?



Solution 1:[1]

Anilist is the title as given in the page's markup. If you see anything else in your browser, check whether the application overrides the title using Javascript. If this is the case, a pure PHP approach won't help to read the page's final title. You either need to run the whole page in a browser and read the output from there, or use a proper API

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nico Haase