const req = await fetch("https://www.youtube.com/watch?v=M0qMgoChzGI");
const html = await req.text();
const title = html.match(/title/gm);
console.log(title);
<?php
function page_title($url) {
$fp = file_get_contents($url);
if (!$fp)
return null;
$res = preg_match("/<title>(.*)<\/title>/siU", $fp, $title_matches);
if (!$res)
return null;
$title = preg_replace('/\s+/', ' ', $title_matches[1]);
$title = trim($title);
return $title;
}
echo page_title("https://www.forobeta.com/");
?>