My csv export displaying html, how to get rid of?

后端 未结 3 850
悲&欢浪女
悲&欢浪女 2020-12-16 08:38

I\'ve seen this asked before and I am having trouble getting this to work properly after trying a number of solutions. The problem is I can\'t get my data to export into a c

3条回答
  •  死守一世寂寞
    2020-12-16 08:45

    The logic for it to work is to construct your php script so that it:

    1. first echoes all the html/javascript... content intended for the browser page like echo ";" (this already uses php's output buffer behind the scenes)
    2. after that cleans the php's output buffer so far, with ob_end_clean() (depending how ob_start() was called this may prevent the previous export) or ob_clean() which just sends content so far to the browser and cleans the buffer without turning it off.
    3. lastly uses this clean output buffer again to export any further content (as downloadable csv in our case) to the browser, like shown above by wowzuzz. So if any html is echoed by the script after that, it will be included in the csv as well.

提交回复
热议问题