how to add google news feed in your websites using PHP

Here we are going to discus how to add google news feed in your websites using PHP ,we know that google is proving XML for news feed here is the link for that

https://news.google.com/rss/search?q=KEYWORD

Here KEYWORD is search query what we are going to add as news feed in your website

This link output xml formatted news feed from that latest websites we can use same xml in your site ,we can use PHP function to convert from one suitable format

Suppose we need to display Cricket World Cup news feed in your website you have to replace KEYWORD with ‘Cricket World Cup’ see example API link below

https://news.google.com/rss/search?q=Cricket+World+Cup&hl=en-IN&gl=IN&ceid=IN:en

Next Step to get the data from the XML

we need to use simplexml_load_file for that

See below code

 


$xml=simplexml_load_file("https://news.google.com/rss/search?q=Cricket+World+Cup&hl=en-IN&gl=IN&ceid=IN:en");
$arrayG = json_decode(json_encode((array)$xml), TRUE);

TO display latest 10 item we have to use

$arrayFeed=array_slice($arrayG['channel']['item'], 0,2);
foreach($arrayFeed as $key=>$value)
{

echo "</pre>
<div class="col-md-9 nfspara">".$value['description']."</div>
"; }

see demo out from the below link
News Feed

Out Put

add google news feed in your websites using PHP

All inside pages are redirecting to http://localhost/dashboard/ in WordPress xampp localhost

When we install WordPress in localhost may face an issue,All inside pages are redirecting to http://localhost/dashboard/ in WordPress localhost

suppose we installed a working WordPress site inside demo folder in htdocs directory and changed the wp_option table siteurl and home option value to http://localhost/demo/

Here is my .htaccess files


RewriteEngine On
RewriteBase /
RewriteRule ^index\.php?$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

here http://localhost/demo/contact_us it is redirecting to http://localhost/dashboard/

To fix this issue you have to change .htaccess files like this

added below code in .htaccess files
RewriteBase /demo/
RewriteRule . /demo/index.php [L]

Here is the .htaccess files


RewriteEngine On
RewriteBase /demo/
RewriteRule ^index\.php?$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /demo/index.php [L]

How to force a website to redirect from http to https using htaccess

Here am going to explain you how force a website redirect from http to https using htaccess files, we all know htaccess is the configuration files normally using in Apache web server to specify redirect rules.we can write our own URL redirect rules and based on we can change the entire website url structure.

Most common use of URL redirects for SEO purpose and better page readability/simplicity, we have lots of rule for redirecting here am going to explain you reule to redirect from http to https using htaccess files

See below force a website redirect from http to https using htaccess
This is full .htaccess to files redirect from http to https

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?tutorialshore\.com
RewriteRule ^(.*)$ https://www.tutorialshore.com/$1 [R,L]

Step 1

First you have to activate RewriteEngine

RewriteEngine On

Step 2

Check if the browser is requesting by http

RewriteCond %{HTTP_HOST} ^(www\.)?tutorialshore\.com

Step 3

if the browser is requesting by http then force to redirect to https

RewriteRule ^(.*)$ https://www.tutorialshore.com/$1 [R,L]


How to force website redirect from http to https using htaccess

Or we can use below code


RewriteEngine On
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Multiselect dropdown with checkboxes demo code in php

Being a developer you may face a situation, have to give multiple select option for the front end user, now it is easy with the help of bootstrap multiselect script we can accomplish that task within 10 minutes. Here am going to explain you Multi select drop down with check boxes demo code in php

here is the Multiselect dropdown with checkboxes demo code in php

Step 1

Files To Include

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css">
</script>

Step 2

HTML Form

<div class="container-fluid"style="text-align: center;margin-bottom:200px;">
<h1>Demo Multiselect Box In PHP</h1>
<div class="row">
<div class="col-md-12" >

<form id="myForm" method="POST">
<input name="current_select_values" type="hidden" value="" id="current_select_values">
<div class="col-md-12" >
 <select size="5" name="current_select[]" multiple="multiple" id="current_select">
 <option value="current1">current1</option>
 <option value="current2">current2</option>
 <option value="current3">current3</option>
 <option value="current4">current4</option>
 <option value="current5">current5</option>
 </select>
 </div><div class="col-md-12" style="margin-top:20px;" >
 <input type="submit" value="Submit" ></div>
</form></div></div></div>

Step 3

Script Files

<script>
$(document).ready(function() {       
	$('#current_select').multiselect({		
		nonSelectedText: 'Select Current'				
	});
});

$(function () {

 
 $('#current_select').multiselect({ 
 buttonText: function(options, select) {
 var labels = [];
 console.log(options);
 options.each(function() {
 labels.push($(this).val());
 });
 $("#current_select_values").val(labels.join(',') + '');
 return labels.join(', ') + '';
 //}
 }
 
 });
});
</script>

Step 4

Post Action


<?php print_r ($_POST['current_select']); ?>

See Demo Code

Multiselect dropdown with checkboxes demo code in php