$url = "https://www.example.com/"; $html = file_get_contents($url); // retrieve HTML content of webpage $title = getTitle($html); // retrieve the title of the webpage echo $title; // output the title of the webpage
include 'simple_html_dom.php'; // import the Simple HTML DOM library $url = "https://www.example.com/"; $html = file_get_html($url); // create a Simple HTML DOM object of the webpage $title = $html->find('title', 0)->plaintext; // retrieve the title of the webpage echo $title; // output the title of the webpageIn this example, we use the Simple HTML DOM library to obtain the title of a webpage located at the specified URL. The file_get_html function creates a Simple HTML DOM object of the webpage, which is then used to locate the title element using the ->find method. The resulting title is then output to the screen. Package/Library: Simple HTML DOM