Set page's title based on another's URL title? [closed]
How do I set my title tag inner HTML to match the Title tag from an URL stored in the variable: $url?
I should somehow retrieve the Title on the url $url and then echo it inside my title tag.
How can I do this?
It's for this site, just in case you are curious: http://www.linkimprov.com/home/开发者_StackOverflow
Thanks
Retrieve the URL (with curl or what have you), parse the HTML, find the title
tag, extract its text, and display it in your own web page.
try this:
$url = 'http://www.google.com';
$htm = file_get_contents($url);
$title = '';
if(preg_match('/\<title\>(.*?)\<\/title\>/',$htm,$match)){
$title = $match[1];
}
echo $title;
//set the current page title to the retrieved title using js
echo '<script>document.title="' . addslashes($title) . '";</script>';
精彩评论