小弟不才,现在才开始学PHP 有很多东西都不懂,希望大虾们给予帮助!!!本想用PHP导入淘宝CSV 文件,但是在修改别人程序的时候不知道怎么办了.因为程序在导入的时候把引号给过滤了.导致数据在前台显示不出图片
前台显示代码如下:
<p style=text-align: center;><img height=350 src=http://www.lsfsw.com/images/upload/Image/5181111111.jpg width=700></p><p style=text-align: center;><img height=676 alt= src=http://www.lsfsw.com/images/upload/Image/222.jpg width=700></p>
通宵了一晚上都没琢磨出哪里出错了. /**
* 解析csv文件
*/
function get_csv_date($file_name){
$str = file_get_contents($file_name);
if($str{0} != "\xFF" || $str{1} != "\xFE"){
return false;
}
//转码
$str = unicodeToUtf8(substr($str, 2));
//切割字符串
$str = preg_replace('/\t\"([^\t]+?)\"\t/es', "'\t\"' . stripslashes(str_replace(\"\n\", \"\", '\\1')) . '\"\t'", $str);
$csv_array = explode("\n", $str);
unset($csv_array[count($csv_array) -1]);
unset($csv_array[0]);
$product_array = array();
if (!empty($csv_array)){
foreach ($csv_array as $k => $v){
// if ($k > $this->product_batch_num){//判断上传数量不能大于指定数量
// break;
// }
$tmp = explode("\t", $v);
//商品名称
$tmp['goods_name'] = str_replace("'",'',str_replace('"','',$tmp[0]));
//库存
$tmp['goods_number'] = intval($tmp[9]);
//商品价格
$tmp['goods_price'] = number_format($tmp[7],2);
if(trim($tmp[35],'"') != ''){
//图片
$tmp['image'] = trim($tmp[35],'"');
}
//商品简介
$tmp['goods_intro'] = str_replace("'",'',str_replace('"','',$tmp[24])); $product_array[] = $tmp;
}
}
return $product_array;
}
希望 大哥们指正啊
前台显示代码如下:
<p style=text-align: center;><img height=350 src=http://www.lsfsw.com/images/upload/Image/5181111111.jpg width=700></p><p style=text-align: center;><img height=676 alt= src=http://www.lsfsw.com/images/upload/Image/222.jpg width=700></p>
通宵了一晚上都没琢磨出哪里出错了. /**
* 解析csv文件
*/
function get_csv_date($file_name){
$str = file_get_contents($file_name);
if($str{0} != "\xFF" || $str{1} != "\xFE"){
return false;
}
//转码
$str = unicodeToUtf8(substr($str, 2));
//切割字符串
$str = preg_replace('/\t\"([^\t]+?)\"\t/es', "'\t\"' . stripslashes(str_replace(\"\n\", \"\", '\\1')) . '\"\t'", $str);
$csv_array = explode("\n", $str);
unset($csv_array[count($csv_array) -1]);
unset($csv_array[0]);
$product_array = array();
if (!empty($csv_array)){
foreach ($csv_array as $k => $v){
// if ($k > $this->product_batch_num){//判断上传数量不能大于指定数量
// break;
// }
$tmp = explode("\t", $v);
//商品名称
$tmp['goods_name'] = str_replace("'",'',str_replace('"','',$tmp[0]));
//库存
$tmp['goods_number'] = intval($tmp[9]);
//商品价格
$tmp['goods_price'] = number_format($tmp[7],2);
if(trim($tmp[35],'"') != ''){
//图片
$tmp['image'] = trim($tmp[35],'"');
}
//商品简介
$tmp['goods_intro'] = str_replace("'",'',str_replace('"','',$tmp[24])); $product_array[] = $tmp;
}
}
return $product_array;
}
希望 大哥们指正啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货