CodeDmx has some collection of PHP Functions.
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" />
Simple Link:
$link = $this->create_link_tag('google.com');
echo $link;
// Gives: <a href="http://google.com">google.com</a>
Link with title
$link = $this->create_link_tag('google.com', 'Visit Google');
echo $link;
// Gives: <a href="http://google.com" title="Visit Google" >google.com</a>
Link with title and HTML attributes
$link = $this->create_link_tag('google.com', 'Visit Google', array(
'class' => 'my_class'
));
echo $link;
// Gives: <a href="http://google.com" title="Visit Google" class='my_class' >google.com</a>
$array =array(
'foo' => 'bar',
'baz' => 'qux'
);
$string = $this->array_to_string($array);
echo $string;
// Gives: foo="bar" baz="qux"
$random = $this->random_string(10);
echo $random;
// Gives: 10 random character string
This method checks for $_SERVER['HTTPS']
$is_https = $this->is_https();
var_dump($is_https);
This method check for $_SERVER['HTTP_X_REQUESTED_WITH']
$is_ajax = $this->is_ajax();
var_dump($is_ajax);
$is_odd = $this->is_odd(5);
var_dump($is_odd);
$is_even = $this->is_even(5);
var_dump($is_even);
$ip = $this->get_ip();
echo $ip;
// Or include a specific header
$ip = $this->get_ip('HTTP_CLIENT_IP');
echo $ip;
$is_mobile = $this->is_mobile();
var_dump($is_mobile);
$browser = $this->know_browser();
echo $browser;
$location = $this->get_location();
echo $location;
$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;
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);
$rank = $this->get_alexa_rank('github.com');
echo $rank;
$rank = $this->get_google_rank('github.com');
echo $rank;
$short = 'https://goo.gl/8SbJTG';
$expand = $this->get_short_url($short);
echo $expand;
// Gives https://github.com/mxra8
$url = $this->short_url('https://github.com/mxra8');
echo $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);