Posts Tagged with converter

Displaying 1-7 of 7 results.
Resolved: PHP filesize MB/KB conversion
posted by admin on June 18, 2016
How can I convert the output of PHP's filesize() function to a nice format with MegaBytes, KiloBytes etc?

  • if the size is less than 1 MB, show the size in KB
  • if it's between 1 MB - 1 GB show it in MB
  • [*] if it's larger - in GBRead more
    Wiki: PHP Convert Hex Color to RGB and RGB to Hexwiki
    posted by admin on April 13, 2016
    Converting certain values back and forth is often necessary when developing functions to help your website work the way you want it to. I needed a function that would convert a hex color to rgb and for some reason it took me a while to figure it out.

    function hex2rgb($hex) {
    $hex = str_replace("#", "", $hex);

    if(strlen($hex) == 3) {
    $r = hexdec(substr($hex,0,1).substr($hex,0,1));
    $g = hexdec(substr($hex,1,1).substr($hex,1,1));
    $b = hexdec(substr($hex,2,1).substr($hex,2,1));
    } else {
    $r = hexdec(substr($hex,0,2));
    $g = hexdec(substr($hex,2,2));
    $b = hexdec(substr($hex,4,2));
    $rgb = array($r, $g, $b);
    //return implode(",", $rgb); // returns the rgb values separated by commas
    return $rgb; // returns an array with the rgb values

    This function works with both shorthand hex codes such as #f00 and longhand hex codes such as #ff0000. It also accepts the number sign (#) just in case. You can see there are two return lines at the end of the function. The first, which is commented out, will return the rgb values separated by a comma. The second, which is the default, will return an array with the rgb values.

    So now with this function in place we can use it like so:

    $rgb = hex2rgb("#cc0");

    The above function would output:

    Array ( [0] => 204 [1] => 204 [2] => 0 )

    Since we are going one way with this, might as well go the other. Here is a function to convert rgb to a hex color:

    function rgb2hex($rgb) {
    $hex = "#";
    $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
    $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
    $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);

    return $hex; // returns the hex value including the number sign (#)

    This function works like so:

    $rgb = array( 255, 255, 255 );
    $hex = rgb2hex($rgb);
    echo $hex;

    The above function would output:

    Read more
    Resolved: Convert an associative array to a simple array of its values in php
    posted by admin on April 7, 2016
    I would like to convert the array:

    Array (
    [category] => category
    [post_tag] => post_tag
    [nav_menu] => nav_menu
    [link_category] => link_category
    [post_format] => post_format


    array(category, post_tag, nav_menu, link_category, post_format)
    Read more
    Resolved: PHP date or datetime to Yesterday, Today
    posted by admin on March 30, 2016
    In my social website, I want to convert datetimes in format, like
    YesterdayRead more
    Resolved: PHP Compose array from string, by comma and space
    posted by admin on March 27, 2016
    I have hashtags, and I want to compose array from my hashtags string. My hashtags format is

    one, two, three, four, five, six, 0909090, ... etc
    Read more
    Resolved: PHP value to boolean true or false convert
    posted by admin on March 6, 2016
    I have some value. I want convert it to boolean, if value is not empty or not NULL, return true, else return falseRead more
    Resolved: markItUp. BBCode Parser with emotions smiles
    posted by admin on December 25, 2015
    altI want to convert convert markItUp BBCode to HTML tags.
    I have smiles too.Read more