over 9 years ago
Hello Reader's! If you having a set of given url's you need just the title of them, then you can use the PHP code below to extract title
- <?php
- function TitleURL($YourURL){
- $str = file_get_contents($YourURL);
- if(strlen($str)>0){
- $str = trim(preg_replace('/\s+/', ' ', $str));
- preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title); // ignore case
- return $title[1];
- }
- }
- //Example:
- echo TitleURL("https://www.wikipedia.org");
- ?>
<?php function TitleURL($YourURL){ $str = file_get_contents($YourURL); if(strlen($str)>0){ $str = trim(preg_replace('/\s+/', ' ', $str)); preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title); // ignore case return $title[1]; } } //Example: echo TitleURL("https://www.wikipedia.org"); ?>
And output will be
0 Comment(s)