Hi, How do I open all HTML file contained in a folder, then search for the title of the page, and save the title in the database? Also, is it possible to do this using functions? Cheers.
Use file_get_contents() to get the contents of the html file as a string. Then you can use this function to get the title. Use the command get_tag_contents($html_content, 'title'): function get_tag_contents($string, $tag) { $startTag = "<{$tag}>"; $endTag = "</{$tag}>"; $start = strpos($string, $startTag); if ($start !== false) { $length = strpos($string, $endTag) - $start; return substr($string, $start, $length); } else { return "Tag not found."; } } PHP: