Note that there are some explanatory texts on larger screens.

plurals
  1. POenclosing double quotes in array
    primarykey
    data
    text
    <p>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.</p> <p>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 <code>'himynameis&amp;quot;,&amp;quot;bob'</code>.</p> <p>My question is, how can I handle the incoming data to cater for '"' being put in the form without breaking my csv file?</p> <p>this is my code for creating the csv log file.</p> <pre><code>@$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 </code></pre> <p>Here is a sample of the incoming array data:</p> <pre><code>Array ( [0] =&gt; Array ( [0] =&gt; 2010/05/17 10:22:27 [1] =&gt; xxx.xxx.xxx.xxx [2] =&gt; title [3] =&gt; """"himynameis","bob" [4] =&gt; example@example.com [5] =&gt; 346346 [6] =&gt; No file attached. ) ) </code></pre> <p>TIA </p> <p>Jared</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload