php - enclosing double quotes in array -


I see it wrong, but I have a form that does its thing (sends emails and more etc) ) But I have also entered some code by entering a simple flat-file CSV log, in which some user has entered the details.

If a user accidentally puts "HeniManimis" for example, then "Bob" will break either the CSV line (since the quotes were not explained) or if I have data on htmlspecialchars () and If I use stripslashes (), then I'll call 'Heninamis & amp; Quot ;, & amp; Quot; Ends with a ugly data value of 'bob' .

My question is, how can I handle the incoming data to put in my form without breaking my CSV file?

This is my code to create a CSV log file.

  @ $ name = htmlspecialchars (trim ($ _ POST ['name'])) @ $ emailCheck = htmlspecialchars (trim ($ _ POST ['email'])); $ $ Heading = htmlspecialchars (trim ($ _ POST ['title'])) @ $ phone = htmlspecialchars (trim ($ _ POST ['phone'])); Function logfile ($ log text) {$ path = 'd: \ logs'; $ Filename = '\ log-' date ('ym', time ()). '.csv'; $ File = $ path $ file name; If (! File_exists ($ file)) {$ logHeader = array ('Date', 'IP_Address', 'Title', 'name', 'customer_email', 'customerpone', 'file'); $ Fp = fopen ($ file, 'a'); Fputcsv ($ fp, $ line); } $ Fp = fopen ($ file, 'a'); Forex currency ($ logText as record $) {fputcsv ($ fp, $ record); }} // log submission for date date $ date = date ("Y / M / D: I: S"); $ ClientIp = getIpAddress (); // Receive client IP address $ nameLog = StripSlash ($ name); $ TitleLog = StripSlash ($ title); If ($ _ files ['uploaded file'] ['error'] == 4) $ filename = "No file is attached."; // Check that the file has been uploaded and $ logText = array (array ("$ date", "$ clientIp", "$ titlelog", "$ nameelog", "$ emailCheck", "$ phone", "$ Return "filename"); Logfile ($ logText); //  

The details of the form to log in are a sample of array data here:

  array ([0] = & gt; Array ([0] = & gt; 2010/05/17 10:22:27 [1] => xxx.xxx.xxx.xxx [2] => Title [3] => "" "Heninius", "Bob" [4] => example@example.com [5] => 346346 [6] => no file attached.))  
< P> TIA

Jared

You can use any " Can "change" in the user input . It is recommended by, and the OpenOffice Calc and Excel doors Other programs will be handled correctly.

You can use str_replace for this. This may be a bit faster than preg_replace:

  Function csv_quote_escape ($ input) {return str_replace ('' ',' '', $ input);}  

Comments