]>
jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - misc/strings.php
3 /** Splits up a string by a space
12 function split($str, $delimiter = " ") : Array
14 return explode($delimiter,$str);
20 * @param mixed $delimiter
23 function glue($array, $delimiter = " ")
26 foreach($array as $str)
30 $string .= $str.$delimiter;
32 return trim($string,$delimiter);
36 * Gets the relative path of the filename
37 * @param mixed $filename
40 function get_relative_path($filename)
42 $relativepath = split($filename, "/");
43 foreach($relativepath as &$tok)
45 $isFinal = ($tok == "html") ? 1 : 0;
50 $relativepath = glue($relativepath,"/");
55 * Returns a `nick` if the string was in the syntax:
60 function show_nick_only($str)
62 $x = strpos($str, "!");
64 $str = substr($str, 0, $x);
69 * Figures out how long ago a given time was
70 * returns string example:
75 function how_long_ago($timestamp)
78 $diff = $now - strtotime($timestamp);
89 foreach ($units as $unit => $text) {
90 if ($diff < $unit) continue;
91 $numberOfUnits = floor($diff / $unit);
92 return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'').' ago';
103 function time_of_day()
105 $timeofday = "day"; // in case something went wrong? lol
107 if ($hour >= 18 || $hour < 4)
108 $timeofday = "evening";
109 else if ($hour >= 4 && $hour < 12)
110 $timeofday = "morning";
111 else if ($hour >= 12 && $hour < 18)
112 $timeofday = "afternoon";
119 * Concatenate a string to a string
121 function strcat(&$targ,$string) : void
122 { $targ
.= $
string; }
126 * Concatenate a string to a string and limits the string to a certain length
128 function strlcat(&$targ,$string,$size) : void
130 strcat($targ,$string);
131 $targ = mb_substr($targ,0,$size);
136 * Prefixes a string to a string
138 function strprefix(&$targ,$string) : void
139 { $targ
= $
string.$targ
; }
143 * Prefixes a string to a string and limits the string to a certain length
145 function strlprefix(&$targ,$string,$size) : void
147 if (sizeof($targ) >= $size)
150 strprefix($targ,$string);
151 $targ = mb_substr($targ,0,$size);
154 /** Checks if the token provided is a bad pointer, by reference
155 * Returns Bool value true if it IS bad
163 function BadPtr(&$tok)
165 if (!isset($tok) || empty($tok) || !$tok || strlen($tok) == 0)
170 /** This function takes a string, tokenizes
171 * it by a space (chr 32), removes the first
172 * word/token, and returns the result.
173 * Mostly used for string manipulation around
177 * rparv(String $sentence)
182 function rparv($string)
184 $parv = split($string);
185 $first = strlen($parv[0]) +
1;
186 $string = substr($string, $first);