Below is the simple function to get class name without namesapce. public function getClassName() { $path = explode(‘\\’, __CLASS__); return array_pop($path); }
Leave a CommentCategory: PHP Code Snippets
Here is simple PHP code snippet to check if a given number is odd or even. Check Number Is Odd Or Even function checkEven($val){ return…
Leave a Comment//here we have one php variable //In javascript/jQuery
Leave a Commentif(!empty($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’) { /* This is one ajax call }
Leave a Commentfunc_get_args() returns an array with all arguments of the current function. PHP5.6 – splat operator Arrays and Traversable objects can be unpacked into argument lists…
Leave a CommentThe array_change_key_case() function changes all keys in an array to lowercase or uppercase. Syntax: array_change_key_case(array,case); array – The array to work on CASE_LOWER – Default…
Leave a Comment<?php $str=”foo,bar,baz,bat”; $arr=explode(“,”,$str); // print_r($arr); ?>
Leave a CommentBelow function takes hex code (e.g. #eeeeee), returns array of RGB values. function hex2rgb( $colour ) { if ( $colour[0] == ‘#’ ) { $colour…
Leave a Comment/** * Get google fonts * * @param integer $amount – Return a chuck of fonts * * @return Array of fonts */ function get_google_fonts(…
Leave a Comment$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, ‘https://devicecloud.digi.com/ws/v1/devices/inventory’); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FLASE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FLASE); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, ‘username:password’); $data = curl_exec($ch); curl_close($ch);…
Leave a Commentin_array() is the function to Check if a value exists in an array using PHP. Here is an example of how it is used: –…
Leave a CommentYou can use the fgets() function with combination of fopne() funciton to read the file line by line. $filename = “inputfile.txt”; if (file_exists($filename) && is_readable…
Leave a CommentHere is the simple PHP function for testing given data is null or empty string. function IsNullOrEmptyString($data){ return (!isset($data) || trim($data)===”); }
Leave a CommentHere is the simple function for detecting spiders and robots. It will return true or false. function is_bot(){ $bots = array( ‘Googlebot’, ‘Baiduspider’, ‘ia_archiver’, ‘R6_FeedFetcher’,…
Leave a Comment