$url = 'https://www.example.com/article-1'; $html = file_get_html($url); $title = $html->find('title', 0)->plaintext; echo $title;
$html = 'This code uses the PHP DOMDocument class to load the HTML code as a document object, finds the title tag using the getElementsByTagName method, and displays the title on the page. In conclusion, PHP Simple HTML DOM Parser is a useful package for article-related functions such as getting the title of an article.Sample Article This is the content of the article.
'; $dom = new \DOMDocument(); $dom->loadHTML($html); $title = $dom->getElementsByTagName('title')->item(0)->nodeValue; echo $title;