ÅÄÖ(瑞典字符)更新问题

时间:2011-12-07 08:41:48

标签: php encoding character

我在jcart中显示ÅÄÖ有一些问题,我不太擅长解释,但如果你看here,你会明白我的意思。

起初这一切似乎都有效,但是如果你更新页面或者去结账那就不行了。如果按“Ta bort”或更新后添加其他项目,将再次正确显示字符。我使用UTF-8作为字符集,我尝试使用ISO-8859-1来解决这些问题,但它显示了另一个符号。不知道问题究竟在哪里,所以请告诉我,如果您有线索,您需要了解更多信息。

观看演示可能会给你一些想法?谢谢!


要显示我的购物车:<?php $jcart->display_cart();?>

这里有一些来自jcart.php(包含文件)的代码:

/**
    * Process and display cart
    */
    public function display_cart() {

        $config = $this->config; 
        $errorMessage = null;

        // Simplify some config variables
        $checkout = $config['checkoutPath'];
        $priceFormat = $config['priceFormat'];

        $id    = $config['item']['id'];
        $name  = $config['item']['name'];
        $price = $config['item']['price'];
        $qty   = $config['item']['qty'];
        $url   = $config['item']['url'];
        $add   = $config['item']['add'];

        // Use config values as literal indices for incoming POST values
        // Values are the HTML name attributes set in config.json
        $id    = $_POST[$id];
        $name  = $_POST[$name];
        $price = $_POST[$price];
        $qty   = $_POST[$qty];
        $url   = $_POST[$url];

        // Optional CSRF protection, see: http://conceptlogic.com/jcart/security.php
        $jcartToken = $_POST['jcartToken'];

        // Only generate unique token once per session
        if(!$_SESSION['jcartToken']){
            $_SESSION['jcartToken'] = md5(session_id() . time() . $_SERVER['HTTP_USER_AGENT']);
        }
        // If enabled, check submitted token against session token for POST requests
        if ($config['csrfToken'] === 'true' && $_POST && $jcartToken != $_SESSION['jcartToken']) {
            $errorMessage = 'Invalid token!' . $jcartToken . ' / ' . $_SESSION['jcartToken'];
        }

        // Sanitize values for output in the browser
        $id    = filter_var($id, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW);
        $name  = filter_var($name, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW);
        $url   = filter_var($url, FILTER_SANITIZE_URL);

        // Round the quantity if necessary
        if($config['decimalPlaces'] === true) {
            $qty = round($qty, $config['decimalPlaces']);
        }

        // Add an item
        if ($_POST[$add]) {
            $itemAdded = $this->add_item($id, $name, $price, $qty, $url);
            // If not true the add item function returns the error type
            if ($itemAdded !== true) {
                $errorType = $itemAdded;
                switch($errorType) {
                    case 'qty':
                        $errorMessage = $config['text']['quantityError'];
                        break;
                    case 'price':
                        $errorMessage = $config['text']['priceError'];
                        break;
                }
            }
        }

        // Update a single item
        if ($_POST['jcartUpdate']) {
            $itemUpdated = $this->update_item($_POST['itemId'], $_POST['itemQty']);
            if ($itemUpdated !== true)  {
                $errorMessage = $config['text']['quantityError'];
            }
        }

        // Update all items in the cart
        if($_POST['jcartUpdateCart'] || $_POST['jcartCheckout'])    {
            $cartUpdated = $this->update_cart();
            if ($cartUpdated !== true)  {
                $errorMessage = $config['text']['quantityError'];
            }
        }

        // Remove an item
        /* After an item is removed, its id stays set in the query string,
        preventing the same item from being added back to the cart in
        subsequent POST requests.  As result, it's not enough to check for
        GET before deleting the item, must also check that this isn't a POST
        request. */
        if($_GET['jcartRemove'] && !$_POST) {
            $this->remove_item($_GET['jcartRemove']);
        }

        // Empty the cart
        if($_POST['jcartEmpty']) {
            $this->empty_cart();
        }

        // Determine which text to use for the number of items in the cart
        $itemsText = $config['text']['multipleItems'];
        if ($this->itemCount == 1) {
            $itemsText = $config['text']['singleItem'];
        }

        // Determine if this is the checkout page
        /* First we check the request uri against the config checkout (set when
        the visitor first clicks checkout), then check for the hidden input
        sent with Ajax request (set when visitor has javascript enabled and
        updates an item quantity). */
        $isCheckout = strpos(request_uri(), $checkout);
        if ($isCheckout !== false || $_REQUEST['jcartIsCheckout'] == 'true') {
            $isCheckout = true;
        }
        else {
            $isCheckout = false;
        }

        // Overwrite the form action to post to gateway.php instead of posting back to checkout page
        if ($isCheckout === true) {

            // Sanititze config path
            $path = filter_var($config['jcartPath'], FILTER_SANITIZE_URL);

            // Trim trailing slash if necessary
            $path = rtrim($path, '/');

            $checkout = $path . '/gateway.php';
        }

        // Default input type
        // Overridden if using button images in config.php
        $inputType = 'submit';

        // If this error is true the visitor updated the cart from the checkout page using an invalid price format
        // Passed as a session var since the checkout page uses a header redirect
        // If passed via GET the query string stays set even after subsequent POST requests
        if ($_SESSION['quantityError'] === true) {
            $errorMessage = $config['text']['quantityError'];
            unset($_SESSION['quantityError']);
        }

        ////////////////////////////////////////////////////////////////////////
        // Output the cart

        // Return specified number of tabs to improve readability of HTML output
        function tab($n) {
            $tabs = null;
            while ($n > 0) {
                $tabs .= "\t";
                --$n;
            }
            return $tabs;
        }

        // If there's an error message wrap it in some HTML
        if ($errorMessage)  {
            $errorMessage = "<p id='jcart-error'>$errorMessage</p>";
        }

        // Display the cart header
        echo tab(1) . "$errorMessage\n";
        echo tab(1) . "<form method='post' action='$checkout'>\n";
        echo tab(2) . "<fieldset>\n";
        echo tab(3) . "<input type='hidden' name='jcartToken' value='{$_SESSION['jcartToken']}' />\n";
        echo tab(3) . "<table border='0'>\n";
        echo tab(4) . "<thead>\n";
        echo tab(5) . "<tr>\n";
        echo tab(6) . "<th colspan='3'>\n";
        echo tab(7) . "<div align='center'><span style='font-size:24px;' id='jcart-title'><br />VARUKORG</span> ($this->itemCount $itemsText) </div>\n";
        echo tab(6) . "</th>\n";
        echo tab(5) . "</tr>". "\n";
        echo tab(4) . "</thead>\n";

        // Display the cart footer
        echo tab(4) . "<tfoot>\n";
        echo tab(5) . "<tr>\n";
        echo tab(6) . "<th colspan='3'>\n";

        // If this is the checkout hide the cart checkout button
        if ($isCheckout !== true) {
            if ($config['button']['checkout']) {
                $inputType = "image";
                $src = " src='jcart/images/checkout.gif' alt='{$config['text']['checkout']}' title='' ";
            }
            echo tab(7) . "<input type='$inputType' $src id='jcart-checkout' name='jcartCheckout' class='jcart-button' value='{$config['text']['checkout']}' /> \n";
        }

        echo tab(7) . "<span id='jcart-subtotal'>{$config['text']['subtotal']}: <strong>" . number_format($this->subtotal, $priceFormat['decimals'], $priceFormat['dec_point'], $priceFormat['thousands_sep']) . " </strong></span>\n";
        echo tab(6) . "</th>\n";
        echo tab(5) . "</tr>\n";
        echo tab(4) . "</tfoot>\n";         

        echo tab(4) . "<tbody>\n";

        // If any items in the cart
        if($this->itemCount > 0) {

            // Display line items
            foreach($this->get_contents() as $item) {
                echo tab(5) . "<tr>\n";
                echo tab(6) . "<td class='jcart-item-qty'>\n";
                echo tab(7) . "<input name='jcartItemId[]' type='hidden' value='{$item['id']}' />\n";
                echo tab(7) . "<input id='jcartItemQty-{$item['id']}' name='jcartItemQty[]' size='1' style='margin:0;padding:0;width:20px;' type='text' value='{$item['qty']}' />\n";
                echo tab(6) . "</td>\n";
                echo tab(6) . "<td class='jcart-item-name'>\n";

                if ($item['url']) {
                    echo tab(7) . "<a href='{$item['url']}'>{$item['name']}</a>\n";
                }
                else {
                    echo tab(7) . $item['name'] . "\n";
                }
                echo tab(7) . "<input name='jcartItemName[]' type='hidden' value='{$item['name']}' />\n";
                echo tab(6) . "</td>\n";
                echo tab(6) . "<td class='jcart-item-price'>\n";
                echo tab(7) . "<span>" . number_format($item['subtotal'], $priceFormat['decimals'], $priceFormat['dec_point'], $priceFormat['thousands_sep']) . "</span><input name='jcartItemPrice[]' type='hidden' value='{$item['price']}' />\n";
                echo tab(7) . "<a class='jcart-remove' href='?jcartRemove={$item['id']}'>{$config['text']['removeLink']}</a>\n";
                echo tab(6) . "</td>\n";
                echo tab(5) . "</tr>\n";
            }
        }

0 个答案:

没有答案