[英]Write a comma in a CSV File with PHP
我正在發送一個csv文件作為標頭,我想使用逗號(不要分開,只是要使用)。 我該怎么辦? 我正在使用PHP,但不能使用fputcsv因為我將其作為標頭發送。
fputcsv
只需在其周圍使用'"'.$value.'"'就可以了。
'"'.$value.'"'
首先將CSV寫入文件,然后通過readfile發送或直接將其寫入輸出流:
readfile
fputcsv( fopen('php://output', 'w+'), array( 'Some text', 'Some text with commas ,,,,,', 'Other text' ) );
然后將打印
"Some text","Some text with commas ,,,,,","Other text"
請注意, fputcsv也將允許您更改定界符和附件,因此,除了將值包裝在引號中之外,還可以僅將定界符更改為例如分號。
請參閱有關fopen支持的包裝器的PHP手冊:
fopen
[英]PHP: Write comma to csv file
[英]write into csv file in php
[英]PHP convert comma delimited string to CSV file
[英]reading large csv file contain comma with php
[英]Create comma delimited .csv file with php
[英]Open CSV with comma or semicolon file in PHP
[英]csv file with delimiter other than comma in php
[英]Php MongoDB Write a CSV File
[英]Escape comma in CSV file
[英]Replacing comma in a csv file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.