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

  • Home
  • SEARCH
  • 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 4261010
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:59:50+00:00 2026-05-21T05:59:50+00:00

Going around in circles so hopefully someone can put me right. Generating a CSV

  • 0

Going around in circles so hopefully someone can put me right.

Generating a CSV through PHP and using my data from MySQL. Data is inputted by the user via TinyMCE so has various “p” tags etc that I obviously need to strip out which I can do successfully, however the string in the csv still gets displayed in various different cells even after being stripped.

I’ve tried using strip_tags() and preg matching “/n” and “/r” and all sorts to remove line breaks but no luck as it still appears on new cells.

I’m using a semi colon as the seperator in the csv.

An example of a string i’m trying to strip all html from would be<p>I would like to join because it looks fun</p><p>&nbsp;</p><p>Help me.</p>. It only happens when their is more than one

tag or something – if the string is simply one line, it works no issues.

Heres the csv code i’m using:

    echo 'Username;Email;Date joined;Reason for joining'."\r\n";

    foreach($users as $user) {
        $csv_data .= $user->username . ';' . $user->email. ';' . date("d/m/y", $user->time_created) . ';' .  $user->reason_for_joining  .';'."\r\n";
    }

    echo $csv_data;

Where am i going wrong?

Thanks guys 🙂

  • 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-21T05:59:50+00:00Added an answer on May 21, 2026 at 5:59 am

    The CSV format has more pitfalls than one might imagine (as you are experiencing). Therefore, don’t reinvent the wheel and use fputcsv, which correctly escapes everything that needs escaping.

    fputcsv expects to write to a file, but you can give it a fake file to write to instead, as outlined here:

    $fp = fopen('php://output', 'w');
    
    $delimiter = ';';
    $headers = array('Username', 'Email', 'Date joined', 'Reason for joining');
    fputcsv($fp, $headers, $delimiter);
    
    foreach ($users as $user) {
        $fields = array($user->...);
        fputcsv($fp, $fields, $delimiter);
    }
    
    fclose($fp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going around in circles with regards to WCF and security, so I'm listing
While going through university and from following the development of SO, I've heard a
I seem to be going around in circles on something I know is really
I don't have much experience with servlets and I've been going around in circles
There is a similar question going around, but it just got the same old
I've got around 750+ users that I'm going to create mailboxes for. Should I
After going through the Appendix A, C# Coding Style Conventions of the great book
I'm going to start a new project - rewriting an existing system (PHP +
I am going to be using C/C++, and would like to know the best
I'm struggling to get sqlldr to import a csv data file into my table,

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.