Posts

Showing posts from December, 2017

export excel file from mysql data in php

<?php include 'conn.php'; $sql = "Select * from `emp`"; $result=mysqli_query($con,$sql); $sep = "\t"; $fp = fopen('report.xls', "w"); $schema_insert = ""; $schema_insert_rows = ""; for ($i = 1; $i < mysqli_num_fields($result); $i++) { $schema_insert_rows.= mysqli_fetch_field_direct($result, $i)->name . "\t"; } $schema_insert_rows.="\n"; echo $schema_insert_rows; fwrite($fp, $schema_insert_rows); while($row = mysqli_fetch_row($result)) { $schema_insert = ""; for($j=1; $j<mysqli_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= strip_tags("$row[$j]").$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ...

online visitor counter

   <?php session_start();      function getUsersOnline() {    $count = 0;         $handle = opendir(session_save_path());    if    ($handle == false) return -1;         while (($file = readdir($handle)) != false) {          if (ereg("^sess", $file)) $count++;    }    closedir($handle);         return $count; } ?> then just call it using this <?php echo $usercount = getUsersOnline(); ?>

How to parse URL and get URI segment in PHP

<?php $exampleURL = "http://iamrohit.in/category/php/hello-world" ; $uriSegments = explode ( "/" , parse_url ( $exampleURL , PHP_URL_PATH ) ) ; echo "<pre>" ; var_dump ( $getUriSegments ) ;   You will see output like this. array ( 4 ) { [ 0 ] => string ( 0 ) "" [ 1 ] => string ( 8 ) "category" [ 2 ] => string ( 3 ) "php" [ 3 ] => string ( 11 ) "hello-world" } In the above example i am using static URL you can get current page url by replacing $exampleURL to $_SERVER[‘REQUEST_URI’] $getUriSegments = explode ( "/" , parse_url ( $_SERVER [ 'REQUEST_URI' ] , PHP_URL_PATH ) ) ;   Now you got all the URI segment in associative array. extract any segment/component you want. echo $uriSegments [ 1 ] ; //returns category echo $uriSegments [ 2 ] ; //returns php echo $uriSegments [ 3 ] ; //returns hello-world For gettin...

Need to simple add pagination woocommerce shop page and category page template wordpress.

// Display 22 products per page. Goes in functions.php add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 4;' ), 20 );

Remove product-category slug in wordpress woocommerce.

<?php /* Plugin Name: Remove product-category slug Plugin URI: https://timersys.com/ Description: Check if url slug matches a woocommerce product category and use it instead Version: 0.1 Author: Timersys License: GPLv2 or later */ add_filter( ' request ' , function ( $vars ) { global $wpdb ; if ( ! empty ( $vars [ ' pagename ' ] ) || ! empty ( $vars [ ' category_name ' ] ) || ! empty ( $vars [ ' name ' ] ) || ! empty ( $vars [ ' attachment ' ] ) ) { $slug = ! empty ( $vars [ ' pagename ' ] ) ? $vars [ ' pagename ' ] : ( ! empty ( $vars [ ' name ' ] ) ? $vars [ ' name ' ] : ( ! empty ( $vars [ ' category_name ' ] ) ? $vars [ ' ...