Notice how Google News has sources on the bottom of each article excerpt.
The Guardian - ABC News - Reuters - Bloomberg
I'm trying to imitate that.
For example, upon submitting the URL http://www.washingtontimes.com/news/2010/dec/3/debt-panel-fails-test-vote/
I want to return The Washington Times
How is this possible with php?
On web browsers, the website title appears at the top of the tab or window, and in search results website titles display as bold hyperlinked texts. A good rule of thumb is to make website titles 50 to 65 characters long and ensure they are clear, as well as descriptive without being truncated.
Use the title attribute for your links when you can provide additional information about that link and/or the page it goes to. For example, if your anchor text just says click here, give your users a better idea of what they'll get if they click on the link (scroll over the “click here” link to see what I mean).
A website title, or title tag, is an HTML element that specifies the content of a webpage. A website title is helpful for both users and search engines. An internet user needs a website title so they can see an accurate and concise description of a page's content before clicking on a link in the SERPs.
You can find your page's title tag within the <head> section of the page's HTML markup.
My answer is expanding on @AI W's answer of using the title of the page. Below is the code to accomplish what he said.
<?php function get_title($url){ $str = file_get_contents($url); if(strlen($str)>0){ $str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside <title> preg_match("/\<title\>(.*)\<\/title\>/i",$str,$title); // ignore case return $title[1]; } } //Example: echo get_title("http://www.washingtontimes.com/"); ?>
OUTPUT
Washington Times - Politics, Breaking News, US and World News
As you can see, it is not exactly what Google is using, so this leads me to believe that they get a URL's hostname and match it to their own list.
http://www.washingtontimes.com/ => The Washington Times
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With