Location: PHPKode > projects > Todo Manager > todo/library/util.lib.php
<?php
function util_empty($value) {
	return ($value === "") || (!isset($value)) || (is_array($value) && (sizeof($value) == 0));
}

function util_getfield($array, $field) {
	return array_key_exists($field, $array)? $array[$field]: NULL;
}

function util_composeurl($url, $params) {
	// disclose the url
	$info = parse_url($url);
	$scheme = isset($info["scheme"])? $info["scheme"]."://": NULL;
	$user = isset($info["user"])? $info["user"]: NULL;
	$pass = isset($info["pass"])? ":".$info["pass"]: NULL;
	$host = isset($info["host"])? (isset($info["user"]) || isset($info["pass"])? "@": NULL).$info["host"]: NULL;
	$path = isset($info["path"])? $info["path"]: NULL;
	$query = isset($info["query"])? $info["query"]: NULL;
	$fragment = isset($info["fragment"])? "#".$info["fragment"]: NULL;
	
	// adding parameters
	foreach ($params as $key => $value) {
		if (util_empty($value))
			continue;
		if (is_array($value)) {
			foreach($value as $id => $v) {
				if ($query != NULL)
					$query .= "&";
				$query .= $key."[".urlencode($id)."]=".urlencode($v);
			}
		} else {
			if ($query != NULL)
				$query .= "&";
			$query .= $key."=".urlencode($value);
		}
	}
	$query = "?".$query;
	$url = $scheme.$user.$pass.$host.$path.$query.$fragment;
	
	return $url;
}

function util_redirect($url, $params = NULL) {
	if (!util_empty($params))
		$url = util_composeurl($url, $params);
	header("Location: ".$url);
	exit();
}

function util_text($text) {
	$text = str_replace("\r", NULL, $text);
	$text = str_replace(array("<ul>\n", "</ul>\n", "<li>\n", "</li>\n"), array("<ul>", "</ul>", "<li>", "</li>"), $text);
	$text = str_replace("\n", "<br />\n", $text);
	return $text;
}

function util_truncate($str, $max_length = 15) {
	if ((strlen($str) > $max_length) && ($max_length > 3))
		$str = substr($str, 0, $max_length - 3)."...";
	return $str;
}

function util_getfilename() {
		return basename($_SERVER["SCRIPT_NAME"]);
}

function util_mail($mailfrom, $mailto, $subject, $message) {
	$headers =
		"MIME-Version: 1.0\n".
		"Content-type: text/plain; charset=iso-8859-1\n".
		"From: ".$mailfrom."\n".
		"Reply-To: ".$mailfrom."\n".
		"X-Mailer: PHP/".phpversion();
	return @mail($mailto, $subject, $message, $headers);
}
?>
Return current item: Todo Manager