CodeDmx Functions

CodeDmx has some collection of PHP Functions.

QR Code

Generating QR Code

$qr_code = $this->get_qr_code('test');
echo $qr_code;
// Gives: <img src="http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=test" />

Generating QR code and adding HTML attributes:

$qr_code = $this->get_qr_code('test',
	$width = 350,
	$height = 350,
	$attributes = array(
		'class' => 'QRCode'
	)
);
echo $qr_code;
// Gives: <img src="http://chart.apis.google.com/chart?chs=350x350&cht=qr&chl=test" class="QRCode" />

Array to String

$array =array(
    'foo' => 'bar',
    'baz' => 'qux'
);
$string = $this->array_to_string($array);
echo $string;
// Gives: foo="bar" baz="qux"

Generate random string

$random = $this->random_string(10);
echo $random;
// Gives: 10 random character string

Detect HTTPS

This method checks for $_SERVER['HTTPS']

$is_https = $this->is_https();
var_dump($is_https);

Detect AJAX

This method check for $_SERVER['HTTP_X_REQUESTED_WITH']

$is_ajax = $this->is_ajax();
var_dump($is_ajax);

Check if number is odd

$is_odd = $this->is_odd(5);
var_dump($is_odd);

Check if number is even

$is_even = $this->is_even(5);
var_dump($is_even);

Get Client IP

$ip = $this->get_ip();
echo $ip;

// Or include a specific header
$ip = $this->get_ip('HTTP_CLIENT_IP');
echo $ip;

Detect mobile

$is_mobile = $this->is_mobile();
var_dump($is_mobile);

Get browser

$browser = $this->know_browser();
echo $browser;

Get Locations

$location = $this->get_location();
echo $location;

Cut string

$string = 'The Fresh Prince of Bel-Air';
$shorten = $this->cut_string($string, 10);
echo $shorten;

// $add_ellipsis '...' at the end of the string
$shorten = $this->cut_string($string, 10, $add_ellipsis = FALSE);
echo $shorten;

// $word_safe to cut or not in the middle
$shorten = $this->cut_string($string, 10, $add_ellipsis = FALSE, $word_safe = TRUE);
echo $shorten;

cURL

Simple GET example

$data = $this->curl('https://api.ipify.org');
var_dump($data);

POST Example

$cURL = $this->curl('http://jsonplaceholder.typicode.com/posts', $method = 'POST', $data = array(
    'title' => 'foo',
    'body' => 'bar',
    'userId' => 1
));
var_dump($cURL);

Custom Headers

$cURL = $this->curl('http://jsonplaceholder.typicode.com/posts', $method = 'POST', $data = FALSE, $header = array(
	'Accept' => 'application/json'
), $return_info = TRUE);
var_dump($cURL);

Get Alexa Rank

$rank = $this->get_alexa_rank('github.com');
echo $rank;

Get Google Page Rank

$rank = $this->get_google_rank('github.com');
echo $rank;

Expand Short URL

$short = 'https://goo.gl/8SbJTG';
$expand = $this->get_short_url($short);
echo $expand;
// Gives https://github.com/mxra8

Short URL

$url = $this->short_url('https://github.com/mxra8');
echo $url;

Embed an url

$string = 'Need more Pidgey for Eminem "Rap God" in Pokémon GO https://www.youtube.com/watch?v=c7_CcBgZ2e4';
echo $this->embed($string);