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 793589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:10:36+00:00 2026-05-14T22:10:36+00:00

I might be looking at this the wrong way, but I have a form

  • 0

I might be looking at this the wrong way, but I have a form that does its thing (sends emails etc etc) but I also put in some code to make a simple flatfile csv log with some of the user entered details.

If a user accidentally puts in for instance ‘himynameis”,”bob’ this would either break the csv row (because the quotes weren’t encapsulated) or if I use htmlspecialchars() and stripslashes() on the data, I end up with a ugly data value of 'himynameis","bob'.

My question is, how can I handle the incoming data to cater for ‘”‘ being put in the form without breaking my csv file?

this is my code for creating the csv log file.

@$name = htmlspecialchars(trim($_POST['name']));
@$emailCheck = htmlspecialchars(trim($_POST['email']));
@$title = htmlspecialchars(trim($_POST['title']));
@$phone = htmlspecialchars(trim($_POST['phone']));


function logFile($logText)
{

    $path = 'D:\logs';
    $filename = '\Log-' . date('Ym', time()) . '.csv';
    $file = $path . $filename;

    if(!file_exists($file))
    {
        $logHeader = array('Date', 'IP_Address', 'Title', 'Name', 'Customer_Email', 'Customer_Phone', 'file');

        $fp = fopen($file, 'a');        

            fputcsv($fp, $line);

    }

    $fp = fopen($file, 'a');


    foreach ($logText as $record) {
    fputcsv($fp, $record);
}




}

//Log submission to file
        $date = date("Y/m/d H:i:s");
        $clientIp = getIpAddress(); //get clients IP address
        $nameLog =  stripslashes($name);
        $titleLog  = stripslashes($title);

        if($_FILES['uploadedfile']['error'] == 4) $filename = "No file attached."; //check if file uploaded and return
        $logText = array(array("$date", "$clientIp", "$titleLog", "$nameLog", "$emailCheck", "$phone", "$filename"));

        logFile($logText); //write form details to log

Here is a sample of the incoming array data:

Array
(
    [0] => Array
        (
            [0] => 2010/05/17 10:22:27
            [1] => xxx.xxx.xxx.xxx
            [2] => title
            [3] => """"himynameis","bob"
            [4] => example@example.com
            [5] => 346346
            [6] => No file attached.
        )

)

TIA

Jared

  • 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-14T22:10:37+00:00Added an answer on May 14, 2026 at 10:10 pm

    You can change any " in user input to "". This is recommended by RFC 4180, and will be handled correctly by OpenOffice Calc and Excel, among other programs.

    You can use str_replace for this. It will probably be slightly faster than preg_replace:

    function csv_quote_escape($input)
    {
      return str_replace('"', '""', $input);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I might be doing this the wrong way when I set up the tables?
This question isn't meant as flame-bait! As it might be apparent, I've been looking
8.2. Fail fast mode I'm looking for where I might configure this option in
Apologies for the long winded title but looking for a solution to what might
Might be a bit of noob question but it's something that's been getting me
Warning : I have just picked up Maven, so things mentioned might be wrong
I have a couple of other questions on here surrounding this area but they
I might be going down the wrong track here, but what I am after
I'm not even sure this is the right way to do this, but I
I know this is a probable open ended question, and I have tried looking

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.