Created
July 8, 2016 10:16
-
-
Save ken-muturi/9147c1da6ebc5d76baaf8503e44e374f to your computer and use it in GitHub Desktop.
mark-util.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This class contains a collection of useful functions used all over the place | |
* */ | |
class Util | |
{ | |
/** | |
* Generate a random string | |
* @param integer $xters string length | |
* @return string random string | |
*/ | |
public static function rand($xters = 5) | |
{ | |
$code = substr(base_convert(hash("ripemd160", mt_rand()), 16, 36), 7, $xters); | |
if ( preg_match('/^0x/i', $code) || preg_match('/^[0-9]+/i', $code) ) | |
$code = self::rand($xters); | |
return $code; | |
} | |
/** | |
* Create a teaser from string. | |
* | |
* This function will eventually be deleted, please use word_limiter() | |
* | |
* @param string $string The | |
* @param int $length The character length of the teaser | |
* @return string | |
* @author imss team | |
* */ | |
public static function teaser($string, $length) | |
{ | |
return substr($string, 0, $length) . (($length < strlen($string)) ? " .." : null); | |
} | |
/** | |
* Wrap output of the print_r() function in <PRE> html tags to enable easier debug selects either the last posted value or the db value (selected value) | |
* | |
* @author imss team | |
* */ | |
public static function printr($var) | |
{ | |
if ($var === FALSE) | |
{ | |
var_dump($var); | |
} | |
else | |
{ | |
echo "<pre>" . print_r($var, 1) . "</pre>"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment