base.php loaded
base.php end
Stayfashion.se
// DB-connection måste redan vara satt upp här!
function safe_query($query="") {
$result = mysql_query($query);
if (!$result) {
die('Query failed: ' . mysql_error() . '
SQL: ' . $query);
}
return $result;
}
function fetch($query) {
return encode_items(mysql_fetch_assoc($query));
}
function sanitize($val) {
$output = str_replace("'", "''", $val);
$output = preg_replace("/(\\\)/si", '\\\\\1', $output);
$output = strip_tags($output);
$output = str_replace(array("\r\n", "\n", "'", "", ""),
array("\\n", "\\n", "\'", "\\x3Cscript\\x3E", "\\x3C/script\\x3E", "\\x3Cnoscript\\x3E", "\\x3C/noscript\\x3E"), $output);
$output = mysql_real_escape_string($output);
return $output;
}
function encode_items($array) {
if (!is_array($array)) return $array;
foreach($array as $key => $value) {
if(is_array($value)) $array[$key] = encode_items($value);
else $array[$key] = utf8_encode($value);
}
return $array;
}
function url($id, $name, $brand) {
return mytrim(cleanurl('/'.$brand.'/'.$name.'/'.$id.'/'));
}
function cleanurl($value) {
return strtolower(preg_replace('/\s+/', '-', str_replace("&","+",str_replace(" "," ",str_replace("*","", $value)))));
}
function mytrim($value) {
$value = trim(ltrim(rtrim($value, '-'), '-'));
return str_replace("/-","/",str_replace("-/","/",$value));
}
// Osv... (lägg till fler om du saknar dem)