Simple URL sharing technique for social sites


Well, this is a very simple technique if you want to put a share button/text for a specific URL to be shared on social sites like facebook, twitter, google+

If you want to share the site to any of the above mentioned social site then just click on the following texts. The technique behind it, is simply passing the URL and/or text with specific pattern as parameter(s) to the share processor URL of one of those social sites.

Share this site in facebook
Tweet this site in twitter
Publicize this site in Google+

Code behind these examples:

<a href=";t=Check This Blog" target="_blank">Share this site in facebook</a>
<a href=" This Blog&amp;url=" target="_blank">Tweet this site in twitter</a>
<a href="" target="_blank">Publicize this site in Google+</a>

Get Google News as JSON by Parsing rss feed


As you know already that, Google News search API has been deprecated few years ago. Still developers need to have Google news as an usable format like JSON for different purpose & development platforms.

Google still provides the news service but in rss format. So, we can have those data for using just by parsing and reformatting them. I wrote a very small php class which will first search  news on Google by specific keywords and load the XML. Then it will parse the XML carefully to dissect parts of news & finally will provide a formatted JSON data set.

As of JSON, all knows that how universal this data format is to implement on several software development platforms. Hope this tiny class help some one 🙂

The class file:

 * Google-News feed parser and JSON provider Class
 * @package None
 * @author Nuhil Mehdy <>
class GoogleNews {

    public $searchQuery = 'Good News';

    public function __construct ($searchQuery) {
            if(!empty($searchQuery)) {
                    $this->searchQuery = $searchQuery;

            $this->numberOfNews = 5;

    public function __toString() {
            return $this->getNews();

    public function setSearchQuery($searchQuery) {
            if(!empty($searchQuery)) {
                    $this->searchQuery = $searchQuery;

    public function setNumberOfNews ($numberOfNews) {
            if(!empty($numberOfNews)) {
                    $this->numberOfNews = (int) $numberOfNews;

    public function getNews () {
            return $this->processNews();

    private function processNews() {
            $loadXml = simplexml_load_file(urlencode(''.$this->searchQuery.'&num='.$this->numberOfNews.'&output=rss'));

            $news = array();

            $i = 0;
            foreach ($loadXml->channel->item as $item)
                preg_match('@src="([^"]+)"@', $item->description, $match);
                $newsSections = explode('</pre>
', $item->description);

 $news[$i]['title'] = (string) $item->title;
 $news[$i]['image'] = $match[1];
 $news[$i]['link'] = (string) $item->link;
 $news[$i]['news_source'] = strip_tags($newsSections[1]);
 $news[$i]['short_story'] = strip_tags($newsSections[2]);


 $result = array('news' => $news, 'status' => '200', 'message' => 'OK');

 return json_encode($result);


Example usage:

$news = new GoogleNews(); 
echo $news->getNews();

You will find this source code on github also. Feel free to use and or fork.