Wednesday, October 11, 2017

CodeIgniter .htaccess

Write below code in .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]


Friday, June 30, 2017

Wordpress change all url by Query string

Note: "First Url is Existing url and second Url is New Url"

UPDATE metikid_metikid.metwp_options SET option_value = replace(option_value, 'https://www.zoylu.com/blog/', 'http://blog.zoylu.com') WHERE option_name = 'home' OR option_name = 'siteurl'



UPDATE metikid_metikid.metwp_posts SET post_content = replace(post_content, 'http://www.zoylu.com/blog/', 'http://blog.zoylu.com');


UPDATE metikid_metikid.metwp_postmeta SET meta_value = replace(meta_value,'http://www.zoylu.com/blog/', 'http://blog.zoylu.com');

Thursday, May 25, 2017

get all input type and there value in a form

<script>function validateRequiredFields()
{
$('#registerForm input').each(
function(index){
var input = $(this);
//alert(input.attr('required'));
if(input.attr('required')=='required'){
var id=input.attr('id');
if(input.val()==''){
$("#"+id).next(".validation").remove();
$("#"+id).css("border", "1px solid red");
$("#"+id).after("<span class='validation' style='color:red;margin-bottom: 20px;'>Please Enter value!</span>");
}else{
$("#"+id).next(".validation").remove();
$("#"+id).css("border", "1px solid green");

}
}
//alert('Type: ' + input.attr('type') + 'Name: ' + input.attr('name') + 'Value: ' + input.val());
}
);


} </script>

call ajax on form submit

<script>
$("#contactForm").submit(function(e) {
//---------------^---------------
e.preventDefault();

var name =$("#name").val();
var surname =$("#surname").val();
var email =$("#email").val();
var dataString = "name="+name+"&surname="+surname+"&email="+email;
$.ajax({
  type: "POST",
  url: "send.php",
  data: dataString,
  cache: false,
  success: function(result){
if(result==1){
$("#mess_sucess").html('');
$('#mess_sucess').show();
var mass='<span style="color:red;margin-bottom: 20px;">Thanks. Your Request Submitted Successfully!</span>';
$('#mess_sucess').html(mass);
document.getElementById('download').click();

}else{
$("#mess_sucess").html('');
$('#mess_sucess').show();
var mass='<span style="color:red;margin-bottom: 20px;">Thanks. Your Request Not Submitted Successfully!</span>';
$('#mess_sucess').html(mass);

}

  }
});

});
</script>

Monday, May 8, 2017

Converting timestamp to time ago in PHP e.g 1 day ago, 2 days ago

Example
echo time_elapsed_string('2013-05-01 00:22:35');
echo time_elapsed_string('@1367367755'); # timestamp input
echo time_elapsed_string('2013-05-01 00:22:35', true);

Output

4 months ago
4 months, 2 weeks, 3 days, 1 hour, 49 minutes, 15 seconds ago

Function 
function time_elapsed_string($datetime, $full = false) {
    $now = new DateTime;
    $ago = new DateTime($datetime);
    $diff = $now->diff($ago);

    $diff->w = floor($diff->d / 7);
    $diff->d -= $diff->w * 7;

    $string = array(
        'y' => 'year',
        'm' => 'month',
        'w' => 'week',
        'd' => 'day',
        'h' => 'hour',
        'i' => 'minute',
        's' => 'second',
    );
    foreach ($string as $k => &$v) {
        if ($diff->$k) {
            $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
        } else {
            unset($string[$k]);
        }
    }

    if (!$full) $string = array_slice($string, 0, 1);
    return $string ? implode(', ', $string) . ' ago' : 'just now';
}

Thursday, April 27, 2017

how to show wordpress blog in custom page

//include('blog/wp-load.php');
include($_SERVER['DOCUMENT_ROOT'].'/blog/wp-load.php');

$recent_posts = wp_get_recent_posts(array(
'numberposts' => 4
));

$blogHtml='';
foreach($recent_posts as $post) {
$jsonData[]=$post;
/* echo "<pre>";
print_r($post);
die; */
$imgUrl='';
if (has_post_thumbnail($post['ID'] ) ){
 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post['ID']), 'single-post-thumbnail' );
$imgUrl= $image[0];

}

$post_date  = date('M d, Y',strtotime($post['post_date']));
$post_excerpt = $post['post_excerpt'];
$url  = get_permalink($post['ID']);
$title  = $post['post_title'];

$blogHtml.='<div class="col-md-3">
<div class="post-inner">
 <div class="hds" style="height:190"> <img class="tabl" src="'.$imgUrl.'" alt="blog" height="190"></div>
 <div class="post-container"> <span class="masonry-post-meta">
<time datetime="2015-02-17"> '.$post_date.'</time>
</span>
<h3> '.ucfirst($title).'</h3>
<div class="post-content">
 <p>'.substr($post_excerpt, 0, 400).' […]</p>
 <div class="read-more">
 <a class="btn btn-primary btn-md pull-right" href="'.$url.'">Read More</a></div>
</div>
 </div>
</div>
 </div>';



}
echo $blogHtml;

Thursday, March 23, 2017

get date between two date

ini_set('date.timezone', 'Asia/Kolkata');
$thisMonth = date('Y-m-01 00:00:00',strtotime('this month'));
$start    = new DateTime('2016-04-01');
$start->modify('first day of this month');
$end      = new DateTime($thisMonth);
$end->modify('first day of next month');
$interval = DateInterval::createFromDateString('1 month');
$period   = new DatePeriod($start, $interval, $end);

foreach ($period as $dt) {
echo $dt->format("Y-m") . "<br>\n";
}