PHP Export data to Taobao helper CSV method to share _php tips

Source: Internet
Author: User

Take a picture first.


Implementation principle

Read the data, write the corresponding segment of the CSV line with the data segment, then save as a CSV, in the latest version of the Taobao Helper test through the

Implementation code

Copy Code code as follows:

function Totaobao ()
{

Load the selected item
$map [' goods_id '] = Array (' In ', $this->returnid ());
$result = $this->showgoods ($map);
Write CSV and save data
$header =iconv (' UTF-8 ', ' GB2312 ', "Baby name, baby category, shop category, new and old degree, province, city, Sale way, baby price, fare increase, baby quantity, validity, freight commitment, flat mail, EMS, Express, payment method, Alipay, invoice, warranty , automatic re-hair, put into the warehouse, window recommended, start time, mood story, baby description, baby picture, baby attributes, group purchase price, minimum number of items, postage template ID, member discount, modification time, upload status, picture status, rebate ratio, new picture, video, sales attribute combination, user input ID string, User input name-value pair, merchant code, sales attribute alias, charger type, baby number ");

Header ("Content-type:text/csv");
Header ("Content-disposition:attachment;filename=ybkgoods.csv");
Header (' cache-control:must-revalidate,post-check=0,pre-check=0 ');
Header (' expires:0 ');
Header (' Pragma:public ');
echo "$header \ n";

Output Data body
foreach ($result as $value)
{
Filter description fields
$desc = Csvdatafilter ("www.yibaikuan.com", $value [' Goods_desc ']);
Intercepting picture file names
$img = Msubstr ($value [' Goods_thumb '],24,25);
Escape

$body =iconv (' UTF-8 ', ' GB2312 ', $value [' Goods_name ']. ",,, 0, Zhejiang, Jinhua, B,". $value [' Shop_price ']. ", 0,". $value [' Goods_ Number ']. ", 14,1,20,20,10,,, 0,0,1,0,1,,,". $desc. ",,,,, 0,0,,100,,0," $img. ": 0:0:|;,,,,,,, 0,");
echo "$body \ n";

}
}

Need to pay attention to a few
1. Coding problems
2. The HTML code filtering problem in the product description
3. Note the path of the picture
Conclusion:
Taobao, Pat, have AH helper generated by the principle of the CSV is similar, there is a need to test.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.