Change currency

Im a noob on this, but how do I change away the dollar sign ($) and replace it with Norwegian Kroner (kr)

Here is the code;

function currency_display($amount) {
$currency = floor($amount*100) % 100;

if ($currency < 10) {
$currency = “0” . $currency;

Do I edit it in here and in case how?

Thanks for helping me out

This is not the complete function. There is no $ anywhere in your code, plus there are two open curly braces ({). Could you please post the complete function? (or the complete file)

Hi and thanks for answer,

Here is the complete code in that actual file called utils.php. There is also another file called cron.php. I will post complete code from that actual file in following post. Thanks.

<?php

/*
        (c) Kaavren
*/

include_once("config.php");
include_once("error.php");

session_start();

$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ("Could not connect to database. Try later<BR>");
@mysql_select_db(DB_NAME, $link);

function error_report($errcode) {
  global $err;
  if ($errcode==10) {                 // mysql error
    $r=mysql_error();
  }
  else {

    $r=$err[$errcode];
  }

    echo "<b>Error: </b>"."$r";

  return 0;
}

function my_query($sql) {
  global $link;
  $result = @mysql_query($sql, $link);
  if ($result) return $result;
  //  error handling here
  if (DEBUG_MODE) { error_report(10); };
//  error_report(10);
  die;

  return false;
}

function currency_display($amount) {
  $currency = floor($amount*100) % 100;

  if ($currency < 10) {
    $currency = "0" . $currency;
  }

  $currency = floor($amount) . "." . $currency;

  return($currency);
}

function valid_email($email) {
  $arr = explode("@",$email);
  $arr2 = explode(".", $email);

  if ((sizeof($arr) != 2) || (sizeof($arr2) != 2)) {
    return(false);
  }

  if (strpos($arr[0], ".") === false) {
    return(true);
  }

  return(false);
}

function check_12hours_limit($lottery_id, $date = 0) {
  global $db_prefix;

  if (!$date) {
    $date = time();
  }
  $r = my_query("select started, duration from " . $db_prefix . "lotteries
  where id='" . mysql_real_escape_string($lottery_id) . "'");

  list($started, $duration) = mysql_fetch_row($r);

  if ($date < ($started + ($duration *24 - 12) * 3600)) return(false); else return(true);
}

// update user IP ad last visit time

$r = my_query("delete from " . $db_prefix . "visits where date < '" . (time() - 24*60*60) ."'");
$r = my_query("insert into " . $db_prefix . "visits(ip,date) values ('" . ip2long($_SERVER['REMOTE_ADDR']) . "','" . time() . "')");

if (isset($_COOKIE['lt_user_login']) && isset($_COOKIE['lt_user_password'])) {
  $r = my_query("select id, password from " . $db_prefix . "users where
  username_hash='" . mysql_real_escape_string($_COOKIE['lt_user_login']) . "' and password_hash='" . mysql_real_escape_string($_COOKIE['lt_user_password']) . "'");
  if (mysql_num_rows($r)) {
    list($user_id, $password) = mysql_fetch_row($r);
    $_SESSION['lt_user_id'] = $user_id;
    $_SESSION['lt_user_pass'] = $password;
    $logged = true;
  }
}


if (isset($_SESSION['lt_user_id'])) {
  $r = my_query("select password from " . $db_prefix . "users where id='" . $_SESSION['lt_user_id'] . "'");
  list($pass) = mysql_fetch_row($r);
  if ($pass != $_SESSION['lt_user_pass']) {
    session_unset();
    exit;
  }


  if (!is_numeric($_SESSION['lt_user_id'])) {
    session_unset();
    exit;
  }

  $r = my_query("update " . $db_prefix . "users set last_visit='" . time() . "',
                 ip='" . ip2long($_SERVER['REMOTE_ADDR']) . "'
                 where id='" . $_SESSION['lt_user_id'] . "'");
  $logged = true;
}
else {
  $logged = false;
}

// save referrer ID

if (isset($_GET['r'])) {
  $_SESSION['lt_referrer_id'] = $_GET['r'];
}

?>
<?php
  include_once("config.php");

  $link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ("Could not connect to database. Try later<BR>");
  @mysql_select_db(DB_NAME, $link);

  function winner($id, $amount) {
    global $db_prefix;
    global $link;

    $r = mysql_query("select t.user_id, t.lottery_id, u.referrer_id
                      from " . $db_prefix . "tickets t, " . $db_prefix ."users u
                      where t.id='$id' and t.user_id=u.id", $link);

    list($user_id, $lottery_id, $referrer_id) = mysql_fetch_row($r);

    $r = mysql_query("select available from " . $db_prefix . "lotteries where id='$lottery_id'", $link);
    list($available) = mysql_fetch_row($r);

    if ($referrer_id) {
      $referrer_amount = floor(5 * $amount)/100;
      $winner_amount = floor(95 * $amount)/100;

      $referrer_amount = floor($referrer_amount * $available)/100;

      $r = mysql_query("insert into " . $db_prefix . "messages(date,user_id,lottery_id,mestype, amount)
                        values('" . time() . "','$referrer_id', '$lottery_id', 'r', '$referrer_amount')", $link);
      $r = mysql_query("insert into " . $db_prefix . "debts(user_id,amount)
                        values('$referrer_id','$referrer_amount')", $link);
    }
    else $winner_amount = $amount;

    $winner_amount = floor($winner_amount * $available)/100;

    $r = mysql_query("update " . $db_prefix . "tickets set won='$winner_amount' where id='$id'", $link);

    $r = mysql_query("insert into " . $db_prefix . "messages(date,user_id,lottery_id,mestype, amount)
                      values('" . time() . "','$user_id', '$lottery_id', 'w', '$winner_amount')", $link);
    $r = mysql_query("insert into " . $db_prefix . "debts(user_id,amount)
                      values('$user_id','$winner_amount')", $link);

    return(0);
  }

  function finish_lottery($id) {
    global $db_prefix;
    global $link;

    $r = mysql_query("select win_percentage, ticket_price from " . $db_prefix . "lotteries where id='$id'", $link);
    list($win_percentage, $ticket_price) = mysql_fetch_row($r);

    $r = mysql_query("select id from " . $db_prefix . "tickets where lottery_id='$id'", $link);
    $players_qty = mysql_num_rows($r);

    $winners_qty = floor($players_qty * $win_percentage / 100);

    if (!$winners_qty) {
      if ($players_qty) $winners_qty = 1; else {
        $r = mysql_query("update " . $db_prefix . "lotteries set ended='" . time() . "' where id='$id'", $link);
        return(1);
      }
    }

    $winner_prize = floor(100 * $ticket_price * $players_qty / $winners_qty) / 100;

    $players = array();

    while(list($ticket_id) = mysql_fetch_row($r)) {
      array_push($players, $ticket_id);
    }

    srand((float)microtime() * 1000000);

    for ($i = 0; $i < $winners_qty; $i++) {
      shuffle($players);
      $ticket_id = array_pop($players);
      winner($ticket_id, $winner_prize);
    }

    $r = mysql_query("update " . $db_prefix . "lotteries set ended='" . time() . "' where id='$id'", $link);

    return(0);
  }

  $r = mysql_query("select id from " . $db_prefix . "lotteries where ended='0'
                   and started+(duration*24*3600) < '" . strtotime(date("Y",time()) . "-" . date("m",time()) . "-" . date("d",time()) . " 23:59:59") . "'", $link);

  while (list($lottery_id) = mysql_fetch_row($r)) {
    finish_lottery($lottery_id);
  }

?>

Just to make it clear, this is coding from a raffle script as you propably see.

I don’t see where the $amount being passed to the currency_display() function (and also used elsewhere) is coming from, so I don’t know it’s datatype. I’m guessing it’s a numeric and not a string. If so, there won’t be any dollar symbols to replace there.

BTW, are dollars and kroners equal in value? You won’t need to do rate conversions?
Also, you really should be using mysqli_ functions instead of the deprecated mysql_ functions.

Can you find where currency_display() is being called and what happens with the return value?