开发者

Set page's title based on another's URL title? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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>';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜