Php帮助,远程<br/>从地址(总PHP noob抱歉)

时间:2016-02-02 17:29:21

标签: php html opencart

我有来自OpenCart的这个php,它在我所有订单通知电子邮件的所有客户地址中不断添加<br />和1个逗号“,”。我只需要弄清楚如何使这个PHP不添加<br />和“,”添加到我的客户在这些电子邮件中的地址,因为它导致我的Endicia网址/运输标签出现问题。我在6个地方看到<br />,但无论我做什么,它都会继续这样做。

'{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
            }

            $find = array(
                '{firstname}',
                '{lastname}',
                '{company}',
                '{address_1}',
                '{address_2}',
                '{city}',
                '{postcode}',
                '{zone}',
                '{zone_code}',
                '{country}'
            );

            $replace = array(
                'firstname' => $order_info['payment_firstname'],
                'lastname'  => $order_info['payment_lastname'],
                'company'   => $order_info['payment_company'],
                'address_1' => $order_info['payment_address_1'],
                'address_2' => $order_info['payment_address_2'],
                'city'      => $order_info['payment_city'],
                'postcode'  => $order_info['payment_postcode'],
                'zone'      => $order_info['payment_zone'],
                'zone_code' => $order_info['payment_zone_code'],
                'country'   => $order_info['payment_country']
            );

            $payment_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));

            if ($order_info['shipping_address_format']) {
                $format = $order_info['shipping_address_format'];
            } else {
                $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
            }

            $find = array(
                '{firstname}',
                '{lastname}',
                '{company}',
                '{address_1}',
                '{address_2}',
                '{city}',
                '{postcode}',
                '{zone}',
                '{zone_code}',
                '{country}'
            );

            $replace = array(
                'firstname' => $order_info['shipping_firstname'],
                'lastname'  => $order_info['shipping_lastname'],
                'company'   => $order_info['shipping_company'],
                'address_1' => $order_info['shipping_address_1'],
                'address_2' => $order_info['shipping_address_2'],
                'city'      => $order_info['shipping_city'],
                'postcode'  => $order_info['shipping_postcode'],
                'zone'      => $order_info['shipping_zone'],
                'zone_code' => $order_info['shipping_zone_code'],
                'country'   => $order_info['shipping_country']
            );

            $shipping_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));

            $this->load->model('tool/upload');

            $product_data = array();

            $products = $this->model_sale_order->getOrderProducts($order_id);

            foreach ($products as $product) {
                $option_data = array();

                $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);

                foreach ($options as $option) {
                    if ($option['type'] != 'file') {
                        $value = $option['value'];
                    } else {
                        $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

                        if ($upload_info) {
                            $value = $upload_info['name'];
                        } else {
                            $value = '';
                        }
                    }

                    $option_data[] = array(
                        'name'  => $option['name'],
                        'value' => $value
                    );
                }

                $product_data[] = array(
                    'name'     => $product['name'],
                    'model'    => $product['model'],
                    'option'   => $option_data,
                    'quantity' => $product['quantity'],
                    'price'    => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
                    'total'    => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value'])
                );
            }

            $voucher_data = array();

            $vouchers = $this->model_sale_order->getOrderVouchers($order_id);

            foreach ($vouchers as $voucher) {
                $voucher_data[] = array(
                    'description' => $voucher['description'],
                    'amount'      => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
                );
            }

            $total_data = array();

            $totals = $this->model_sale_order->getOrderTotals($order_id);

            foreach ($totals as $total) {
                $total_data[] = array(
                    'title' => $total['title'],
                    'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
                );
            }

            $data['orders'][] = array(
                'order_id'           => $order_id,
                'invoice_no'         => $invoice_no,
                'date_added'         => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
                'store_name'         => $order_info['store_name'],
                'store_url'          => rtrim($order_info['store_url'], '/'),
                'store_address'      => nl2br($store_address),
                'store_email'        => $store_email,
                'store_telephone'    => $store_telephone,
                'store_fax'          => $store_fax,
                'email'              => $order_info['email'],
                'telephone'          => $order_info['telephone'],
                'shipping_address'   => $shipping_address,
                'shipping_method'    => $order_info['shipping_method'],
                'payment_address'    => $payment_address,
                'payment_method'     => $order_info['payment_method'],
                'product'            => $product_data,
                'voucher'            => $voucher_data,
                'total'              => $total_data,
                'comment'            => nl2br($order_info['comment'])
            );
        }
    }

    $this->response->setOutput($this->load->view('sale/order_invoice.tpl', $data));
}

public function shipping() {
    $this->load->language('sale/order');

    $data['title'] = $this->language->get('text_shipping');

    if ($this->request->server['HTTPS']) {
        $data['base'] = HTTPS_SERVER;
    } else {
        $data['base'] = HTTP_SERVER;
    }

    $data['direction'] = $this->language->get('direction');
    $data['lang'] = $this->language->get('code');

    $data['text_shipping'] = $this->language->get('text_shipping');
    $data['text_picklist'] = $this->language->get('text_picklist');
    $data['text_order_detail'] = $this->language->get('text_order_detail');
    $data['text_order_id'] = $this->language->get('text_order_id');
    $data['text_invoice_no'] = $this->language->get('text_invoice_no');
    $data['text_invoice_date'] = $this->language->get('text_invoice_date');
    $data['text_date_added'] = $this->language->get('text_date_added');
    $data['text_telephone'] = $this->language->get('text_telephone');
    $data['text_fax'] = $this->language->get('text_fax');
    $data['text_email'] = $this->language->get('text_email');
    $data['text_website'] = $this->language->get('text_website');
    $data['text_contact'] = $this->language->get('text_contact');
    $data['text_from'] = $this->language->get('text_from');
    $data['text_to'] = $this->language->get('text_to');
    $data['text_shipping_method'] = $this->language->get('text_shipping_method');
    $data['text_sku'] = $this->language->get('text_sku');
    $data['text_upc'] = $this->language->get('text_upc');
    $data['text_ean'] = $this->language->get('text_ean');
    $data['text_jan'] = $this->language->get('text_jan');
    $data['text_isbn'] = $this->language->get('text_isbn');
    $data['text_mpn'] = $this->language->get('text_mpn');

    $data['column_location'] = $this->language->get('column_location');
    $data['column_reference'] = $this->language->get('column_reference');
    $data['column_product'] = $this->language->get('column_product');
    $data['column_weight'] = $this->language->get('column_weight');
    $data['column_model'] = $this->language->get('column_model');
    $data['column_quantity'] = $this->language->get('column_quantity');
    $data['column_comment'] = $this->language->get('column_comment');

    $this->load->model('sale/order');

    $this->load->model('catalog/product');

    $this->load->model('setting/setting');

    $data['orders'] = array();

    $orders = array();

    if (isset($this->request->post['selected'])) {
        $orders = $this->request->post['selected'];
    } elseif (isset($this->request->get['order_id'])) {
        $orders[] = $this->request->get['order_id'];
    }

    foreach ($orders as $order_id) {
        $order_info = $this->model_sale_order->getOrder($order_id);

        // Make sure there is a shipping method
        if ($order_info && $order_info['shipping_code']) {
            $store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);

            if ($store_info) {
                $store_address = $store_info['config_address'];
                $store_email = $store_info['config_email'];
                $store_telephone = $store_info['config_telephone'];
                $store_fax = $store_info['config_fax'];
            } else {
                $store_address = $this->config->get('config_address');
                $store_email = $this->config->get('config_email');
                $store_telephone = $this->config->get('config_telephone');
                $store_fax = $this->config->get('config_fax');
            }

            if ($order_info['invoice_no']) {
                $invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
            } else {
                $invoice_no = '';
            }

            if ($order_info['shipping_address_format']) {
                $format = $order_info['shipping_address_format'];
            } else {
                $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
            }

            $find = array(
                '{firstname}',
                '{lastname}',
                '{company}',
                '{address_1}',
                '{address_2}',
                '{city}',
                '{postcode}',
                '{zone}',
                '{zone_code}',
                '{country}'
            );

            $replace = array(
                'firstname' => $order_info['shipping_firstname'],
                'lastname'  => $order_info['shipping_lastname'],
                'company'   => $order_info['shipping_company'],
                'address_1' => $order_info['shipping_address_1'],
                'address_2' => $order_info['shipping_address_2'],
                'city'      => $order_info['shipping_city'],
                'postcode'  => $order_info['shipping_postcode'],
                'zone'      => $order_info['shipping_zone'],
                'zone_code' => $order_info['shipping_zone_code'],
                'country'   => $order_info['shipping_country']
            );

            $shipping_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));

            $this->load->model('tool/upload');

            $product_data = array();

            $products = $this->model_sale_order->getOrderProducts($order_id);

            foreach ($products as $product) {
                $product_info = $this->model_catalog_product->getProduct($product['product_id']);

                $option_data = array();

                $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);

                foreach ($options as $option) {
                    if ($option['type'] != 'file') {
                        $value = $option['value'];
                    } else {
                        $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

                        if ($upload_info) {
                            $value = $upload_info['name'];
                        } else {
                            $value = '';
                        }
                    }

                    $option_data[] = array(
                        'name'  => $option['name'],
                        'value' => $value
                    );
                }

                $product_data[] = array(
                    'name'     => $product_info['name'],
                    'model'    => $product_info['model'],
                    'option'   => $option_data,
                    'quantity' => $product['quantity'],
                    'location' => $product_info['location'],
                    'sku'      => $product_info['sku'],
                    'upc'      => $product_info['upc'],
                    'ean'      => $product_info['ean'],
                    'jan'      => $product_info['jan'],
                    'isbn'     => $product_info['isbn'],
                    'mpn'      => $product_info['mpn'],
                    'weight'   => $this->weight->format($product_info['weight'], $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point'))
                );
            }

            $data['orders'][] = array(
                'order_id'           => $order_id,
                'invoice_no'         => $invoice_no,
                'date_added'         => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
                'store_name'         => $order_info['store_name'],
                'store_url'          => rtrim($order_info['store_url'], '/'),
                'store_address'      => nl2br($store_address),
                'store_email'        => $store_email,
                'store_telephone'    => $store_telephone,
                'store_fax'          => $store_fax,
                'email'              => $order_info['email'],
                'telephone'          => $order_info['telephone'],
                'shipping_address'   => $shipping_address,
                'shipping_method'    => $order_info['shipping_method'],
                'product'            => $product_data,
                'comment'            => nl2br($order_info['comment'])
            );
        }
    }

    $this->response->setOutput($this->load->view('sale/order_shipping.tpl', $data));
}

public function api() {
    $json = array();

    // Store
    if (isset($this->request->get['store_id'])) {
        $store_id = $this->request->get['store_id'];
    } else {
        $store_id = 0;
    }

    $this->load->model('setting/store');

    $store_info = $this->model_setting_store->getStore($store_id);

    if ($store_info) {
        $url = $store_info['ssl'];
    } else {
        $url = HTTPS_CATALOG;
    }

    if (isset($this->session->data['cookie']) && isset($this->request->get['api'])) {
        // Include any URL perameters
        $url_data = array();

        foreach ($this->request->get as $key => $value) {
            if ($key != 'route' && $key != 'token' && $key != 'store_id') {
                $url_data[$key] = $value;
            }
        }

        $curl = curl_init();

        // Set SSL if required
        if (substr($url, 0, 5) == 'https') {
            curl_setopt($curl, CURLOPT_PORT, 443);
        }

        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLINFO_HEADER_OUT, true);
        curl_setopt($curl, CURLOPT_USERAGENT, $this->request->server['HTTP_USER_AGENT']);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_URL, $url . 'index.php?route=' . $this->request->get['api'] . ($url_data ? '&' . http_build_query($url_data) : ''));

        if ($this->request->post) {
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->request->post));
        }

        curl_setopt($curl, CURLOPT_COOKIE, session_name() . '=' . $this->session->data['cookie'] . ';');

        $json = curl_exec($curl);

        curl_close($curl);
    }

    $this->response->addHeader('Content-Type: application/json');
    $this->response->setOutput($json);
}

}

1 个答案:

答案 0 :(得分:1)

你的str_replace函数向后。

应该是这样的。

$payment_address = str_replace( '<br />', array("\r\n", "\r", "\n"), $string );

这会将所有<br />代码替换为array("\r\n", "\r", "\n")变量中的$string