<?php
function magic_quote_alter($value,$quote='') {
if ($quote = '"') {
$value = str_replace('"','\"',$value);
} elseif ($quote= "'") {
$value = str_replace("'","\'",$value);
}
if (!get_magic_quotes_gpc()) {
return addslashes($value);
} else {
return $value;
}
}
function ternary($current,$item1,$item2) {
if ($current == $item1) {
return $item2;
} else {
return $item1;
}
}
function getResultDiv($value,$type='error') {
// Formats successful or error results whether they are in an array or a snippet.
if ($type == 'success') {
$class = 'success-div';
} elseif ($type == 'test') {
$class = 'test-div';
} else {
$class = 'error-div';
}
if (is_array($value)) {
for ($i = 0; $value[$i] != ''; $i++) {
$result_div .= '<li>' . $value[$i] . '</li>';
}
if ($result_div != '') {
$result_div = '<div class="' . $class . '"><ul>' . $result_div . '</ul></div>';
}
} else {
if ($value != '') {
$result_div = '<div class="' . $class . '">' . $value . '</div>';
}
}
return $result_div;
}
function showSelected($value,$to_match) {
if ($value == $to_match) {
return ' selected ';
} else {
return '';
}
}
function listArray($array) {
while ($var = each($array)) {
printf ("Key <b>%s</b> has the value of: <b>%s</b><br>", $var['key'], $var['value']);
}
}
if(!function_exists('str_split')){
function str_split($str,$length=1){
$cnt = strlen($str);
for ($i=0; $i<$cnt; $i+=$length) {
$array[]= substr($str,$i,$length);
}
return $array;
}
}
function checkValidChars($string,$valid_chars) {
$string_array = str_split($string);
$valid_chars_array = str_split($valid_chars);
$i = 0;
while ($string_array[$i] != '') {
if (!in_array($string_array[$i],$valid_chars_array)) {
return false;
}
$i++;
}
return true;
}
?>