Deprecated: Calling get_class() without arguments is deprecated in /var/www/html/wp-includes/class-wp-http.php on line 329 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/class-wp-http.php:329) in /var/www/html/wp-includes/feed-rss2.php on line 8 php – Saurabh Gandhe https://saurabhgandhe.com I bring your ideas to life! Mon, 09 Sep 2019 21:26:25 +0000 en-US hourly 1 https://wordpress.org/?v=6.3.1 144541061 PHP Wrapper for NewsAPI.org https://saurabhgandhe.com/php-wrapper-for-newsapi-org/ Mon, 09 Sep 2019 21:21:02 +0000 https://saurabhgandhe.com/?p=374 I came across a nice website NewsAPI.org that gives you access to news from around the world. You can filter based on country, language and category.

Check it out: https://newsapi.org/

Documentation: https://newsapi.org/docs

They didn’t have a PHP wrapper, and I was getting bored, so I scribbled a wrapper using curl to use it in PHP applications.

Add the API Key Generated using a Free Account(it has some limitations).

Look at the documentation to see the usage, as all I do is pass the same parameters to the curl request.

include 'config.php'; #set the api key here#
$newsAPIClient = new newsAPIClient;
$topHeadlines = $newsAPIClient->getSources(array('country' => 'in'));
$topHeadlines = $newsAPIClient->getEverything(array('q' => 'bitcoin', 'pageSize' => 5));

You can download the sourcecode here.

There is no warranty associated and is not intended for production use. I would add some comments and format code before use.

]]>
374
There’s a better way for if($var == 5). It’s .. https://saurabhgandhe.com/theres-a-better-way-for-ifvar-5-its/ Thu, 11 Jul 2019 20:53:11 +0000 http://saurabhgandhe.com/?p=218 Ever wandered which one is correct?

if($var ==5) or if (5==$var)?

Why?

Although, you might see a warning in your IDE, it’s unlikely you will get any error for saying if($var = 5) , but if you have a habit of using the other way, you will get an error for assigning variable to constant.

<?php

What you use

if($var == 5){}

What you should use

if(5==$var){}

Why you should follow me ?

because, you may do this > if($var=5){}

and only this will generate error > if(5=$var){}

Happy Coding!

]]>
218