Git Product home page Git Product logo

helper_function's Introduction

helper_function

Helper function

    function custom_fetch($var,$field){
        if ($var!=null) {
            return $var[0]->$field;
        }
    }

    function image($link){
        if ($link==null) {
            return site_url("private/images/placeholder.png");
        }else{
            return site_url($link);
        }
    }
    
    function filter($value){
        $capitalize="";
        $rmv_scor=str_replace("_"," ", $value);
        if (mb_detect_encoding($rmv_scor)!='UTF-8') {
            $capitalize=ucwords($rmv_scor);
        }else{
            $capitalize=$rmv_scor;
        }
        
        return $capitalize;
    }



function view_more($string,$amount,$link=null,$text="View More"){
        $strings=explode(" ", $string);

        if (count($strings)<=$amount) {
            return(implode(" ",$strings));
        }
        else{
            $out_string=array();
            for ($i=0; $i<$amount; $i++) { 
                $out_string[]=$strings[$i];
            }
            $final=implode(" ",$out_string).'<div class="view_more"> <a href="'.$link.'">'.$text.'</a> </div>';
               return($final);
        }
}

function message_length($strlength){
	$messLen = 0;
	if( $strlength <= 160){ $messLen = 1; } 
	else if( $strlength <= 306){ $messLen = 2; } 
	else if( $strlength <= 459){ $messLen = 3; } 
	else if( $strlength <= 612){ $messLen = 4; }
	else if( $strlength <= 765){ $messLen = 5; }
	else if( $strlength <= 918){ $messLen = 6; }
	else if( $strlength <= 1071){ $messLen = 7; }
	else if( $strlength <= 1080){ $messLen = 8; }
	else { $messLen = "Equal to an MMS."; }
	return $messLen;
}
//Function for Dynamic Language Start
function caption($index){
    $CI = & get_instance();
    // load model
    $CI->load->model('action');
    // use model method
    $val = $CI->action->read('site_meta',array('meta_key'=>'language'));

    $label_lang = config_item('label_lang');

    return $label_lang[$index][$val[0]->meta_value];
}
//Function for Dynamic Language End

//Function updating site information
function site_update(){
    $CI = & get_instance();
    // load model
    $CI->load->model('action');
    // use model method
    $data = array(
        'meta_value' => date('Y-m-d H:i:s a')
    );
    $where = array(
        'meta_key' => 'update_date'
    );
    $CI->action->update('site_meta',$data,$where);
}
//Function updating site information

//Array Differance
function arrayDiff($a,$b){
	$c = array_diff($a, $b);
	$d = array_diff($b, $a);
	$e = array_merge($c,$d);
	$f = array_unique($e);
	return $f;
}
//Array Differance

    function selected($v1,$v2){
        if($v1==$v2){
            echo "selected";
        }
    }

    function checked($v1,$v2){
        if($v1==$v2){
            echo "checked";
        }
    }

    function valid_equal($v1,$v2){
        if($v1==$v2){
            return true;
        }
        return false;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.