Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6319511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:49:05+00:00 2026-05-24T15:49:05+00:00

I am dealing with a rather large web app in PHP with smarty. One

  • 0

I am dealing with a rather large web app in PHP with smarty. One part of it requires spitting out a report in CSV format. I set all required headers and pass data to the smarty template:

$template->assign('headers', $report->get_headers());
$template->assign('data', $report->get_data());

My template looks like this:

{strip}
{assign var="newline" value="\n"}
{foreach from=$headers item=h name=hdr}
    "{$h|replace:'"':'""'}"
    {if !$smarty.foreach.hdr.last},{/if}
{/foreach}
{$newline}
{if trim($warntext) != ''} 
    "{$warntext|replace:'"':'""'}"
    {$newline}
{/if}
{foreach from=$data item=row name=res}
    {foreach from=$row item=v name=val}
        "{$v|replace:'"':'""'}"
        {if !$smarty.foreach.val.last},{/if}
    {/foreach}
    {if !$smarty.foreach.res.last}{$newline}{/if}
{/foreach}
{/strip}

Everything works fine – except one problem. Somewhere there’s one space character being printed in the very beginning of the output, so the first row in the CSV (headers) looks like this:

[space-char]"ID","Name","Reg date",...

As a result, Excel messes up the first heading: A1 cell contains ' "ID"' (without the single quotes, of course). Obviously, there’s something somewhere printing this space char – but how can I find it? I tried tracing the execution of the report (there are dozens of php files being required from inside each other – with a total of more than 10K lines of code to get the report). I tried searching for echo and print and print_r – but nothing. I’m getting desperate now. Any help would be greatly appreciated.

P.S. Please do not comment/answer with “let them just fix the output file”, as these are external clients I’m dealing with: I can’t tell them to ‘please edit the file before opening in Excel’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:49:07+00:00Added an answer on May 24, 2026 at 3:49 pm

    Try looking for whitespaces right before opening <?php tags and right after closing ?> tags (if used at all). These are common places to have spaces accidently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my PHP app, I get dates from the MySQL database, when I format
Rather than trying to piece out the individual pains I'm dealing with, I want
I'm dealing with a rather frustrating bug. My ultimate goal is to have an
One issue that comes up during Pinax development is dealing with development versions of
I am dealing with a very strange and rather simple problem about 2 days
I am creating a mobile version of a rather large and photo heavy site.
I am dealing with large integral numbers in my script and I want to
I was considering using UnmanagedMemoryStream rather than MemoryStream for dealing with incoming (and perhaps
When dealing with an enumeration containing none, one or many of an item the
Dealing with an employee that went over my head

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.