删除从php到csv输出的£符号

时间:2014-02-04 10:49:40

标签: php csv

我需要从PHP文件生成的CSV文件中删除£符号。

我在搜索时遇到了这个问题

money_format("%!.2n", 123)

但不知道必须将其包含在php文件中

    <?php
    //Connection to database
    mysql_connect("ip","user","pass");
    mysql_select_db("dbname");

$result = mysql_query("SELECT

`oc_order`. order_id AS id,
DATE(`oc_order`. date_added) AS Date,
oc_order_product . total AS 'Total',
`oc_order`. payment_method AS Pay_Method,
'' AS PO_Number,

`oc_order`. payment_firstname AS Billing_First_Name,
`oc_order`. payment_lastname AS Billing_Last_Name,
`oc_order`. payment_company AS Billing_Company_Name,
`oc_order`. payment_address_1 AS Billing_Address_Line_1,
`oc_order`. payment_address_2 AS Billing_Address_Line_2,
`oc_order`. payment_city AS Billing_Town,
`oc_order`. payment_zone AS Billing_County,
`oc_order`. payment_country AS Billing_Country,
`oc_order`. payment_postcode AS Billing_Post_Code,

`oc_order`. shipping_firstname AS Shipping_First_Name,
`oc_order`. shipping_lastname AS Shipping_Last_Name,
`oc_order`. shipping_company AS Shipping_Company_Name,
`oc_order`. shipping_address_1 AS Shipping_Address_Line_1,
`oc_order`. shipping_address_2 AS Shipping_Address_Line_2,
`oc_order`. shipping_city AS Shipping_Town,
`oc_order`. shipping_zone AS Shipping_County,
`oc_order`. shipping_country AS Shipping_Country,
`oc_order`. shipping_postcode AS Shipping_Post_Code,

`oc_order`. email AS Email,
`oc_order`. telephone AS Phone,

`oc_order`. shipping_method AS Shipping_Method,
`oc_order`. comment AS Customer_comment,

oc_order_product . name AS 'Product Description',
oc_order_product . quantity AS 'Quantity',
oc_order_product . price AS 'Unit Price',
oc_product . sku AS SKU,
time(`oc_order`. date_added) AS Order_Time,
oc_product. cost AS Cost,

oc_order_product . order_product_id AS 'order_product_id',
oc_order_product . product_id AS 'product_id'

FROM `oc_order`
INNER JOIN oc_order_product ON `oc_order`.order_id=oc_order_product.order_id
INNER JOIN oc_product ON oc_order_product.product_id=oc_product.product_id
WHERE order_status_id > 0 ORDER BY `oc_order`.order_id") or die(mysql_error());//`);RAND()
if (!$result) die('Sorry, I was unable to any fetch records. Try again').mysql_error();

$num_fields = mysql_num_fields($result);

$headers = array();

// Creating headers for output files
for ($i = 0; $i < $num_fields-2; $i++)
{
    $headers[] = mysql_field_name($result , $i);
}
$headers[]="Subtotal";
$headers[]="Other totals";
$headers[]="VAT";
$headers[]="Totals";
$headers[]="Product Options";
$headers[]="SKU";
$headers[]="Discount Code";
$headers[]="EU Tax ID";
//var_dump($headers);
$o=array(10,20,3000,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,300,310,260,270,330,380,290,340,350,360,370,30,280,320,285,286);
$order=$o;
array_multisort($order,$headers);
array_pop($headers);
array_pop($headers);
$filename="Orders/output.csv";
$fp = fopen($filename, 'w');
if ($fp && $result)
{
// name of file with date
    //$filename = "Filename-".date('Y-m-d').".csv";

        // Setting header types for csv file.
        //header('Content-Type: text/csv');
        //header('Content-Disposition: attachment; filename='.$filename);
        //header('Pragma: no-cache');
        //header('Expires: 0');
        fputcsv($fp, $headers);
}

str_replace("£", "", $str);

$rez=array();

while ($row = mysql_fetch_row($result)){$order=$o;
//var_dump($row);
//$rez[]=$row;
$q="select payment_tax_id
from oc_order where order_id='".$row[0]."'";
$x=mysql_query($q) or die(mysql_error());
$tax="";
while ($r=mysql_fetch_row($x)){
$tax=$r[0];
}


$q="select title,text
from oc_order_total where order_id='".$row[0]."'";
$x=mysql_query($q) or die(mysql_error());
$total="";
$subtotal="";
$vat="";
$totalt="";
while ($tot=mysql_fetch_row($x)){
if($tot[0]=="Sub-Total")$subtotal=$tot[1];
else
if ($tot[0]=="VAT (20%)")$vat=$tot[1];
else 
if ($tot[0]=="Total")$totalt=$tot[1];
else
$total.=$tot[0].": ".$tot[1]."; ";
}
$total=substr($total,0,-2);

$q="select name, value, product_option_value_id from oc_order_option where order_product_id='".$row[33]."'";
$x=mysql_query($q) or die(mysql_error());
$options="";

$search=array();

while ($tot=mysql_fetch_row($x)){
//var_dump($tot);
$options.=$tot[0].": ".$tot[1]."; ";
$search[]=$tot[2];
}
$options=substr($options,0,-2);
//echo ($total."<br>".$options."<br>");
$search=implode(":",$search);

$sku2=$row[30];

$q="select sku from oc_product_option_relation where product_id='".$row[34]."' and var='".$search."'";
$x=mysql_query($q) or die(mysql_error());
//$options="";
while ($tot=mysql_fetch_row($x)){
//var_dump($tot);
$sku2=$tot[0];
//$options.=$tot[0].": ".$tot[1]."; ";
}
//$options=substr($options,0,-2);
//echo ($total."<br>".$options."<br><br>");
//echo "<br><br>";
array_pop($row);
array_pop($row);
$row[]=$subtotal;
$row[]=$total;
$row[]=$vat;
$row[]=$totalt;

$row[]=$options;
$row[]=$sku2;
$row[]='';
$row[]=$tax;
//var_dump($order);
//var_dump($row);
array_multisort($order,$row);
//var_dump($row);
array_pop($row);
array_pop($row);
fputcsv($fp, array_values($row));
}


fclose($fp);

?>

0 个答案:

没有答案