postgresql - php remove whitespace during export to csv -


itemprop = "text">

After I trim the values ​​of the empty space as I output, the query results from PostgreSQL in my PHP script Having trouble The line of comment is an array returning from a print_r ();

  & lt ;? Php $ db = pg_connect ("host = local host dbname = user trial = test password = test"); $ Result = pg_query ($ db, "SELECT * table WHERE field = 'test'"); $ Array = pg_fetch_all ($ result); // array ([0] = & gt; array ([ID_NUMBER] => 214 [country] => Zanzibar [area] => Unguja [site] => Chumbe Island Coral Park (CHICOP ) [Username] = & gt; n) [1] = & gt; array ([ID_NUMBER] => 213 [country] => Zanzibar [area] => Unguja [site] = & gt; ; Chumbe Island Coral Park (CHICOP) [user name] => N ^ ("Trim", $ array_explode); $ array_implode = burst ("", $ array_trimmed); not set ($ array_explode); // **************************************************************** .csv ',' W '); foreach ($ fields as $ array_implode) {fputcsv ($ fp, $ c) Fields);} fclose ($ FP);?  

If I remove the lines between the stars (just simultaneously CSV output, lots of unnecessary white space. Without code> implode () and tried without it, this is driving me to the wall and any help would be greatly appreciated.

I was able to work your code ng:

   214; 'country' = 'Zanzibar', 'field' => 'Unguja', 'site' = & gt; ; 'Chumbe Island Coral Park', 'Username' = & gt; 'n'), 1 = & gt; array ('ID_NUMBER' => 213, 'country' = & gt; Zanzibar ' , 'Field' = & gt; 'Unguja', 'site' => 'Chumbe Island Coral Park', 'Username' = & gt; 'n')); $ Fp = fopen ('file.csv', 'w'); Forex currency ($ array as $ field) {$ array_trimmed = array_map ("trim", $ field); Fputcsv ($ fp, $ array_trimmed); } Fclose ($ fp); Production from file.csv:  
  214, Zanzibar, Unguja, "Chumbe Island Coral Park (CHICOP)", N213, Zanzibar, Anguja, "Chunkey Island Coral Park" (chicope), n  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -