Top Questions:

  • 5 years-11 months

    How to compress CSS files using PHP

    • Category : php
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    When you’re using a sophisticated design, CSS files can quickly become very long, and takes time to load. I have compiled interresting ways of compressing CSS files by using PHP.

    (1.)
    <link rel="stylesheet" type="text/css" media="screen" href="/style.css.php"/>
    Once you successfully rename your css files, edit it and add the following code at the beginning of the file:
    <?php if(extension_loaded('zlib')){ob_start('ob_gzhandler');} header("Content-type: text/css"); ?>
     

    2 Answers

    View More

    vikas image

    Name: vikas

    Experiance: 5 years-11 months

    answered
    Jul 01, 2016 at 07:11

    Then, add the next line to the very bottom and save the file.
    <?php if(extension_loaded('zlib')){ob_end_flush();}?>
     
  • 3 years-4 months

    Refresh Particular Div On Ajax Success

    • Category : ajax
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    if you want to refresh single div not a page than you can use this code

    <div class="avlfrom">
     <span class="leftgap">
    <a  href="javascript:void(0);"  class="remove_field" id="1">delete</a>
    <a  href="javascript:void(0);"  class="remove_field" id="2">delete</a>
    <a  href="javascript:void(0);"  class="remove_field" id="3">delete</a>
    </span>
    </div>
    <script>
           $(document).on('click','.remove_field',function(){
            if (confirm("Are you sure you want to delete")) {
                   var id=$(this).attr('id');
                   $.ajax({
           url: "ajax_page.php",            
                 type: "POST",
                       data: 'id=' id,
                 success: function(data) {
                              $(".avlfrom").load(location.href " .avlfrom>*","");
          },
           }); 
       return false;
                    }
                 });
    
    <script>
  • 5 years-11 months

    UI Datepicker be made to disable Saturdays and Sundays with custom date

    • Category : jquery
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    I use a datepicker for choosing an appointment day.I want to exclude Saturdays and Sundays from the available choices. Can this be done? If so, how?

    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <input name="datenew" type="text" id="datepicker">
    <script>
    var unavailableDates = ["21-6-2016","22-6-2016","23-6-2016","24-6-2016"];
    function unavailable(date) {
      var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
        dmy = date.getDate()   "-"   (date.getMonth()   1)   "-"   date.getFullYear();
      var closedDays = [[Saturday],[Sunday]];
     for (var i = 0; i < closedDays.length; i  ) {
        if (day == closedDays[i][0]) {
          return [false];
       }
    
     }
        if (jQuery.inArray(dmy, unavailableDates) == -1) {
            return [true, ""];
        } else {
            return [false, "", "Unavailable"];
        }
    }
    jQuery(function() {
      jQuery( "#datepicker" ).datepicker({    
        changeMonth: true,
        changeYear: true,
       dateFormat: 'dd MM yy',   
        autoclose: true,
        minDate:  2,
        firstDay: 1,
        beforeShowDay: unavailable
      });
    
    });
    </script>
  • 3 years-4 months

    Display limited words

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    Display limited o of word from a string using this code

    echo mb_strimwidth('It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English', 0, 50, "...");
     
  • 3 years-4 months

    Last Week Start And End Date

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    Get last week start and end date in php

    $previous_week = strtotime("-1 week  1 day");
    
    $start_week = strtotime("last sunday midnight",$previous_week);
    $end_week = strtotime("next saturday",$start_week);
    
    $start_week = date("Y-m-d",$start_week);
    $end_week = date("Y-m-d",$end_week);
    
    echo $start_week.' '.$end_week ;
     
  • 5 years-11 months

    woocommerce cart not working for without login

    • Category : wordpress
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    I am fairly new to woocommerce and although the other day the add to cart and cart page was displaying fine. I am now finding that going to my cart page brings up a blank page.

    add this code in function.php
    add_filter('woocommerce_add_to_cart', 'custome_add_to_cart');
    function custome_add_to_cart() {
        global $woocommerce;
     $woocommerce->session->set_customer_session_cookie(true);
    }
     
  • 5 years-11 months

    PHP mysql search multiple tables using a keyword

    • Category : php
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    I have two tables in my database which are: user and event for PHP mysql search multiple tables using a keyword

    create table : event like
    CREATE TABLE IF NOT EXISTS `event` (
      `id` int(32) unsigned NOT NULL AUTO_INCREMENT,
      `email` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
      `event_name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
    then create table : user like
    CREATE TABLE IF NOT EXISTS `user` (
      `id` int(32) unsigned NOT NULL AUTO_INCREMENT,
      `email` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
      `name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
    mysql query
    $query = "(SELECT name,email,'new_name' as type FROM user WHERE name LIKE '%te%') UNION (SELECT event_name,email,'new_event_name' as type FROM event WHERE event_name LIKE '%te%')";
    mysql_query($query);
    output
    name     email                 type
    denis terzo   abcd@gmail.it       new_name
    Andrea    abcddd.abcddd@gmail.com   new_name
    test    abcddd.vvvv@gmail.com     new_event_name
    test    abcddd.vvvv@gmail.com     new_event_name
    ram     abcddd.vvvv@gmail.com     new_name
     
  • 5 years-11 months

    woo-commerce cart item session start and destroy after 30 Min.

    • Category : wordpress
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    woo-commerce cart item session start and destroy after 30 Min

    <?php
    
    global $woocommerce;
    if (!isset($_SESSION['EXPIRES']) || $_SESSION['EXPIRES'] < time()) {
     $woocommerce->cart->empty_cart(); 
    } else {
      $_SESSION['EXPIRES'] = time() 1800;
    }
    
  • 3 years-4 months

    Print Data using Ajax

    • Category : ajax
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    print your custom data or field using ajax

    function printinvoice(id){
         $.ajax({
           url: "sample.php",            
                type: "POST",
           data: "print_id=" id,
          success: function(data) {
         newWin= window.open();
                            newWin.document.write(data);
                            newWin.document.close();
                            newWin.focus();
                            newWin.print();
                             newWin.close();
          },
      error: function() {
         
          }
       }); 
    }
  • 5 years-11 months

    Return all dates or time between two dates in an array

    • Category : php
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    Return all dates or time between two dates in an array

    print_r(createDateTimeRangeArray('2007-01-15 11:15:00', '2007-01-20 18:15:00','  1 day','d/m/Y h:i:s A'));
    
    
    function createDateTimeRangeArray($start,$end,$step = '  30 minutes',$output_format = 'H:i') {
      $range = array();
     if (is_string($start) === true) $start = strtotime($start);
     if (is_string($end) === true ) $end = strtotime($end);
      if ($start > $end) return createDateTimeRangeArray($end, $start);
      do {
        //$range[] = date('Y-m-d', $start);
       $range[] = date($output_format, $start);
        $start = strtotime($step, $start);
      }
     while($start < $end);
      return $range;
    }