Fputcsv() results strip quotes.
For now, I question a MySQL database with phpMyAdmin and export the results to a comma delimited CSV file.
It works fine but I need to automate this process if I can.
The php script that I created using fputcsv() but by default it adds quotation marks around the text strings that contain spaces.
And the service that I work with does not quotes in the CSV file.
Results with fputcsv():
1234,"prod name with spaces", 29.95,/path/filename.zip,1gb,4320
Expected result:
1234, prod name with spaces,29.95,/path/filename.zip,1gb,4320
<? PHP
mysqli_select_db ($con, "myproducts") or die ("no data found");
$result = mysqli_query ($con, "SELECT prodcode, AutoCAD price, dload_url, size, downloads expiry_time WHERE dload_url LIKE" %value% ' ORDER BY prodcode DESC "");
$row = mysqli_fetch_array ($result, MYSQLI_ASSOC);
$fp = fopen ('myfile.csv', 'w');
While ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {}
fputcsv() ($fp, $row);
}
fclose ($FP);
? >
Any ideas?
Nancy O.
A much simpler solution is to use fwrite() instead of fputcsv():
$fp = fopen ('myfile.csv', 'w');
While ($row = mysqli_fetch_array ($result, MYSQLI_NUM)) {}
fwrite ($fp, implode (', ', $row). « \r\n ») ;
}
fclose ($FP);
The reason fputcsv() insists on an envelope is to prevent problems if the text contains the same character as the delimiter. If you are certain that the value of AutoCAD will never contain commas, this solution will work. But if a product name always contains commas, you're screwed.
Tags: Coding Corner
Similar Questions
-
TabBar clicks result in &; quot; #&; quot; in the browser title bar
I have a Flex application with a TabBar as the main navigation. When I click on a tab, change the title in the title bar of IE7 on «#» Is it possible to prevent this?
Thank you.I use [knowingly] deep linking, so I guess that is not a problem to make this change.
The only difference I noticed was when I unchecked the box that history.css and history.js files are no longer included in the HTML wrapper file. I have my own custom wrapper, so I simply removed their page, and this problem has been resolved.
Thanks for your help!
-
Hi all
I am new to FDMEE and I'm trying to create a script to import in order to remove the quotes when importing data in FDMEE.
I did some research and I found the syntax in order to remove the quotes.
(Thanks
)Link:- FDMEE import quotes
But for some reason it doesn't work is not for me.
Could someone help me with the code please.
Code: -.
def fRemoveQuotes (strField, strRecord):
return strField.replace('"','')
Error: -.
2014-09-16 16:38:38, 351 [AIF] INFO: beginning of the process FDMEE, process ID: 464
2014-09-16 16:38:38, 351 [AIF] INFO: recording of the FDMEE level: 4
2014-09-16 16:38:38, 351 [AIF] INFO: FDMEE log file: XXX_XXXX\outbox\logs\XXX_XXXX-XXX_XXXX_464.log
2014-09-16 16:38:38, 351 [AIF] INFO: location: RSG (Partitionkey:29)
2014-09-16 16:38:38, 351 [AIF] INFO: name: aug period (period key: 8/31/14-12:00 AM)
2014-09-16 16:38:38, 351 [AIF] INFO: name of the category: real (category key: 2)
2014-09-16 16:38:38, 351 [AIF] INFO: name rule: RSG (rule ID:60)
2014-09-16 16:38:41, 174 [AIF] INFO: Jython Version: 2.5.1 (Release_2_5_1:6813, September 26 2009, 13:47:54)
[JRockit (R) Oracle (Oracle Corporation)]
2014-09-16 16:38:41, 174 [AIF] INFO: Java platform: java1.6.0_37
2014-09-16 16:38:41, 174 [AIF] INFO: log the file encoding: UTF-8
2014-09-16 16:38:43, 811 INFO [AIF]: - START IMPORT STEP -
2014-09-16 16:38:55, 823 INFO [AIF]: file name: XXX_TEMP
2014-09-16 16:38:56, INFO 072 [AIF]: ERPI - 105011:EPMERPI - the name of the log file: XXX_XXXX\outbox\logs\XXX_XXXX-XXX_XXXX_464.log
2014-09-16 16:38:56, INFO 072 [AIF]: ERPI - 105011:EPMERPI - LOADID:PARTKEY:CATKEY:RULEID:CURRENCYKEY:FILEPATH:464; 29:2:60: [NO]: XXX_XXXX/inbox\RSG
2014-09-16 16:38:56, INFO 072 [AIF]: ERPI - 105011:EPMERPI - ImportTextData - Start
2014-09-16 16:38:56, 119 [AIF] INFO: ERPI - 105011:EPMERPI - the name of the log file: XXX_XXXX\outbox\logs\XXX_XXXX-XXX_XXXX_464.log
2014-09-16 16:38:56, 119 [AIF] INFO: ERPI - 105011:EPMERPI - JythonInterpreter instantiation
2014-09-16 16:38:56, 275 [AIF] INFO: 105039:EPMERPI - the name of the log file: XXX_XXXX\outbox\logs\XXX_XXXX-XXX_XXXX_464.log
2014-09-16 16:38:56, 275 [AIF] INFO: 105039:EPMERPI - run the file: XXX_XXXX/data/scripts/import/Quotes.py
2014-09-16 16:38:56, 275 [AIF] INFO: 105039:EPMERPI - run the file: XXX_XXXX/data/scripts/import/Quotes.py
2014-09-16 16:38:56, 291 [AIF] INFO: ERPI-105011:EPMERPI - XXX_TEMP file name
periodKey2014-08-31
2014-09-16 16:38:56, ERROR 291 [AIF]: 105039:EPMERPI - 105042:EPMERPI - error evaluating script.
null
2014-09-16 16:38:56, ERROR 291 [AIF]: 105039:EPMERPI - 105042:EPMERPI - error evaluating script.
null
2014-09-16 16:38:56, 291 [AIF] INFO: ERPI - 105011:EPMERPI - PROCESS ID: 464
PARTITIONKEY: 29
IMPORT GROUP: RSG
FILE TYPE: DELIMITED
SEPARATOR:.
SOURCE FILE: XXX_TEMP
TREATMENT OF CODES:
-----------------------------------------------------------------------------------
EMPTY... Line is empty or empty.
NN................ Non-Numeric, amount field contains non-numeric characters.
TC................ Conversion, type amount field could not be converted to a number.
ZP................ Zero suppress, amount field contains a value of 0 and zero suppress is turned on.
FIELD TO JUMP... SKIP field value has been found
NULL VALUE ACCOUNT... Account field is null
JUMP FROM A SCRIPT... Skippered by Script
[SCRIPT SKIPED] "454", "000000", "000" "000", "0000", "00", "000", "11391001", "AUG-14", "-0000000019977.59"»»
Filled lines: 0
Lines rejected: 1
2014-09-16 16:38:56, 291 [AIF] INFO: ERPI - 105011:EPMERPI - MODE ARCHIVE: null
2014-09-16 16:38:56, 291 [AIF] INFO: ERPI - 105011:EPMERPI - start file archiving:
2014-09-16 16:38:56, 291 [AIF] INFO: ERPI - 105011:EPMERPI - name of the Archive file: 46420140831
2014-09-16 16:38:56, 291 [AIF] INFO: ERPI - 105011:EPMERPI - by deleting the source file: XXX_TEMP
2014-09-16 16:38:56, 291 [AIF] INFO: ERPI - 105011:EPMERPI - file not deleted: XXX_XXXX\inbox\RSG\XXX_TEMP
2014-09-16 16:38:56, 306 [AIF] INFO: ERPI - 105011:EPMERPI - ImportTextData - end
2014-09-16 16:38:56, 306 [AIF] INFO: ERPI - 105011:EPMERPI - Total time required to import in ms = 234
2014-09-16 16:38:56, 306 [AIF] INFO: ERPI - 105011:EPMERPI - JythonInterpreter release
2014-09-16 16:38:56, 431 [AIF] INFO:
Import of Source data for the period "aug.
2014-09-16 16:38:56, 790 INFO [AIF]: generic data lines imported from Source: 0
2014-09-16 16:38:56, 790 [AIF] INFO: Total of lines of data from the Source: 0
2014-09-16 16:38:57, 430 [AIF] INFO:
Map data for the period "aug.
2014-09-16 16:38:57, ERROR 430 [AIF]: error: no record exists for the period "aug.
2014-09-16 16:38:57, 461 FATAL [AIF]: error in CommMap.updateTDATASEG_T_TDATASEGW
Traceback (most recent call changed):
File "< string >", 1775, in updateTDATASEG_T_TDATASEGW the line
RuntimeError: Error: no record exists for the period "aug.
2014-09-16 16:38:57, 461 FATAL [AIF]: error in CommMap.updateTDATASEG_T_TDATASEGW
Traceback (most recent call changed):
File '< string >", line updateTDATASEG_T_TDATASEGW, 1982
RuntimeError: [u "error: no record exists for the period 'aug'" "]
2014-09-16 16:38:57, 601 FATAL [AIF]: error in data COMM plan.
Thanks in advance.
Kind regards
RSG.
Hello
as suggested by @BeauDReynolds you can replace the quotes before importing the file.
If you want to use scripts to import for each dimension (is not necessary for the amount in your case), you can use this script:
def parseDoubleQuotes (strField, strRecord):
#strip quotes
return strField.strip('"')
the tape will remove initial and end of double quotes
You function should work as well, but you must ensure that both matches name function name and script.
You function name is fRemoveQuotes while your script is quotes.
Rename each function in quotes def or a script for fRemoveQuotes.py
I hope this helps.
-
SOLR search returns 0 results if expression is of double quotes
If having a search result that looks like this:
Perspectives on the Office Assistant
July 28, 2014 - to turn on the out of Office Assistant: on the Tools menu, click out of Office Assistant. In the out of Office Assistant dialog box, select the automatic replies option send out of office. If you want to specify a fixed time and date Select range only send it during this time box range. Then set the start time, and then assign it...
When I do this research, I get 10 back, including the above results.
< cfsearch
name = "qTechTips".
collection = "" #collection # ""
criteria = "secondary_id_i:24 out of office.
OrderBy = 'sort_date_s desc '.
/ >
But when I do a phrase search for "out of Office":
< cfsearch
name = "qTechTips".
collection = "" #collection # ""
criteria = "secondary_id_i:24 «out of Office"»
OrderBy = 'sort_date_s desc '.
/ >
or
< cfsearch
name = "qTechTips".
collection = "" #collection # ""
criteria = "secondary_id_i:24"out of the Office.
OrderBy = 'sort_date_s desc '.
/ >
I get 0 results. What I am doing wrong? I would like to make an exact expression for what is in the body, not the 'title '.
I'm on ColdFusion 11, update 3
Escape the quotes didn't help. I already read examples of search solr by Adobe, but that doesn't help me much. I don't know if it is documented in the CF documentation anywhere (I couldn't find it). I have worked for me after watching the Apache Solr documentation, it is that you need to add "+" between words in the sentence:
<>
name = "qTechTips".
collection = "" #collection # ""
criteria = "secondary_id_i:24" Out + of + desktop "" "
OrderBy = 'sort_date_s desc '.
/>
Waiting for my users to enter '+' is a bit much, but I know they can handle to put quotes on the phrases they want an exact match. After some googling, this is my solution to automatically add the '+' between the exact phrase for the treatment of the cfsearch (if you have a better solution, please let me know):
<>
name = "qTechTips".
collection = "" #collection # ""
criteria = "" #solr_criteria # ""
OrderBy = 'sort_date_s desc '.
/>
#solr_criteria #.
-
SOLR Search return fuzzy results in the search terms in quotes
I'm trying to get an output of the Solr search
If I have a search for "Fund Administrator", who should return only the 2 files, I get 5 registers 3 results of research being the administration of Fund
How we prevent blurred returns the values in quotes?
qSearch equlas "Fund Administrator", including the quotes
< cfsearch
collection = "#sCollection #
name = "search".
"contextHighlightBegin = ' < span class ="the search format">"
contextHighlightEnd = "</span >.
contextPassages = '3 '.
criteria = "' title: #qSearch #^ 2 #qSearch #" "
status = "structSearchPublic."
suggestions = 'never '.
>
TIA
Search fuzzy
< cfsearch="" name="mysolrsearch" ="" collection="mysolr" ="" criteria="Fund Administrator~">
-
Get the set of results within single quotes.
How can I get this result set in single quotes asSQL>SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE='TABLE'; OBJECT_NAME ---------------------------------------------------------------------------- BONUS CHILD DEPT EMP EMP_DTL ENTRY
Published by: GarryB on May 12, 2009 04:07OBJECT_NAME ---------------------------------------------------------------------------- 'BONUS' 'CHILD' 'DEPT' 'EMP' 'EMP_DTL' 'ENTRY'
SQL> select ''''||ename||'''' from emp; ''''||ENAME| ------------ 'SMITH' 'ALLEN' 'WARD' 'JONES' 'MARTIN' 'BLAKE' 'CLARK' 'SCOTT' 'KING' 'TURNER' 'ADAMS' 'JAMES' 'FORD' 'MILLER' 14 rows selected. SQL>
-
The results of a substr quotes
Hello all,.
I have a string I need to use a where clause clause.
Result 22ABCD123456%SELECT translate(replace(substr('22/ABCD/123456//WXYZ/',0,14),' ', ''),'@/-.','@') || '%' FROM DUAL
I need the result either "% 22ABCD123456".
Thanks for the tips.SELECT '''' || translate(replace(substr('22/ABCD/123456//WXYZ/',0,14),' ', ''),'@/-.','@') || '%''' FROM DUAL
-
In MXML 'txtDes.text = {txtSource.text'} how in still result
ex.
MXML:
< mx:TextInput id = "txtDes" / >
< mx:TextInput id = text = "{txtDes.text}" / 'txtSource' >
AS: how? for the same resultvar txtDesc:TextInput = new TextInput();
txtDesc.addEventListener (Event.CHANGE, fillTxtSource);
this.addChild (txtDesc);var txtSource:TextInput=newTextInput();
this.addChild (txtSource);public void fillTxtSource(event:Event):void
{
txtSource.text = event. CurrentTarget.text;
} -
RemoteObject (PHP) don't trigger &; quot; result &; quot; event
I have a RemoteObject with 'result' two managers (one for each remote service call).
When getItemList is triggered, getItemListResultHandler fires automatically after.
(Both are verified with break points)
However...
GetItem is triggered, getItemResultHandler if NOT triggered automatically after.
(Both are verified with break points)
How is it?
(I checked that my php returns data in both cases)
Here is my Service RO mxml file and my PHP file:Unless the "db" PHP class you are showing here is not complete, there is no getList() method in this class, only getItem() and getItemList(). If you listen for an event from a non-existent method:
ro.getList.addEventListener ("result", getItemResultHandler);
ro.getList.addEventListener ("fault", roFaultHandler);TS
-
Hi there, we have several list/menu on our website form and want to know if theres a way to stop all the 'Please select' results to come through?
"Choose" comes from my because that user hasent selected a result in the list menu.
See you soon
MalhypThanks, Dooza, I found a few sites on them javascript form validation. He will give a go today.
Thank you Gary White, worked perfectly. I tried everything except for that.
Thanks Brégent it helps me explain my darn self.Soon :)
-
Could someone remind me please how do I remove the quotes when you return a numeric string
That is to say when I write set member("xxxxxxx").line [1]
the return is "15".
I need just the number without "" thank youthe value (member("xxxxxxx").line [1])
Or if the text must be a whole number (no decimal point)
set an integer (member("xxxxxxx").line [1])
-
When I copy and paste, the results are stripped of formatting.
It's weird, I can copy and paste, but all pasting is wiped clean of formatting, underlying formulas (in Excel), hyperlinks, etc. This happens in all programs (Word, Excel, gmail) and when the copy/paste between programs (Word to gmail).It must be a global setting of XP SP3. I tried to roll back the computer a week, but the problem exists (not sure when it started).Any ideas?Thank youWhen you paste that you get a symbol down at the bottom that gives you paste options and select keep source formatting?
http://www.excelforum.com/Excel-General/764099-copy-paste-losing-formatting.html
This link mentions him "style" of excel, find out what the problem described is the same as yours. "
http://help.WUGNET.com/office/copying-tab-loses-formattingftopic-1165433-DAYS0-orderasc-8.html
This link mentions him ' theme'of the spreadsheet. "
http://www.howtogeek.com/HOWTO/28478/copy-and-paste-in-Outlook-without-messing-up-your-formatting/
He mentions how to keep the updated source in the form an email
http://answers.Microsoft.com/en-us/Office/Forum/Excel
Finally, if none of the help above, it is the link to the forum office.
-
Warning quota IMAP but I have cleaned already and its use is very low
I get a warning of Quota IMAP (101%) on one of my gmail email accounts.
I read the articles on cleaning and avoid Quota IMAP problems and have done what I can delete and move e-mails.
But my space usage report shows that I use only 36MB for this account which seems really small.
(my main Gmail account using 8.8 GB and I do not receive a warning.)what I missed or where can I turn?
Peter
Gmail will also save all e-mails, both sent and received in 'all mail '.
Deletion of an e-mail from a folder does not result removes the email in "all mail".
Basically, all letters, incoming and outgoing are saved in the folder "all messages".
Labels can be applied to create a visual effect to appear as in other folders, for example: Inbox or one that you create.So to delete an e-mail from for example: Inbox simply deletes the "Inbox" label and still leaves the email in "all messages".
-
Inconsistent results Spotlight
I've known inconsistent results of Spotlight with OS X servers for a year or so now. I worked on that with Yosemite and El Capitan.
What is happening is that Spotlight does not see inside some files scattered in various actions. The problem is consistent if the search of a customer attached or on the server itself. It has many, many of these records.
I deleted it. Index files V100-focus on volumes several times with the following process:
sudo mdutil - a-i off
sudo rm - rfv. Spotlight-V100 (I run on each volume)
sudo mdutil - a-i on
sudo mdutil - Ea
However after letting the Spotlight re-indexing it does not fix things.
I think next reset the ACL on the volume where the data is stored. I first want to make sure that what I'm doing, that's enough:
sudo chmod-r/path/to/volume n
Then set the permissions for the shares as it should.
Suggestions or comments?
You happen to have the system during a rebuild Spotlight log tail? If Yes, have you seen errors, files or records which failed to index, or all mdworker default processes? The system log can provide valuable data as to why Spotlight does not complete.
Then, if you are going to strip the ACL, you will also remove user _spotlight. This system is essential for the proper functioning of the projector. Make sure that when you go to spread your new ACLs that account _Spotlight is listed as an ACE inherited. All files and folders on your part must contain this account from the ACL table service.
And finally, don't forget to watch the POSIX permissions. If you have restrictive permissions POSIX, you may have implemented a condition in which the mdworker process simply can not cross your data structure. Search for files located at 700 or files located at 600. Perhaps considered using the propagation process to restore all the POSIX permissions standard umask.
I hope this helps.
Reid
Apple Consultants Network
Author - "El Capitan Server - Foundation Services.
Author - "El Capitan Server - Collaboration & control»
Author - "El Capitan Server - Advanced Services '.
: IBooks exclusively available in Apple store
-
How to Config? All I get is a Google search result.
I need to open on Config to access certain log files. When I put "on the Config" (without the quotes) in the address bar all I get is a Google search result.
http://youtu.be/F20GnUuHOg8~please go to this video on how to get to about: config. There is a video done personally.
Maybe you are looking for
-
My e-mail delete button has disappeared how do I get it back?
My e-mail delete button has disappeared how do I get it back? I was clear some cookies, I thought caused trouble and now my button remove is gone and my computer has been acting
-
Need USB drivers for old Equium L40 - 10U PSL41E running Vista 32-bit
Hi all I think that my USB driver is corrupted. I found the ChipSet, LAN and BIOS drivers for my old PSL41E Equium L40 - 10U running Vista 32 bit. However, I have not found the USB drives I need. USB drivers are contained in the ChipSet, BIOS or LAN
-
SSRS 2012 export to CSV with no data by generating coma separated with an empty value
I have a report that have no data due to parameter motor (both have true noheader configuration). In SSRS 2005 its generate empty csv file and for SSRS 2012 his record still generate with coma and an empty value, something like this: ,,,, Those that
-
Trying to set up wireless printer, after installation successful, received the message; I'm not allowed to make changes... see network admin?
-
I tried everyway possible to get graphs of swichable working on my Vaio VPCSB1AGX/B, but nothing works. I did a clean install of Windows 8 Pro and it's really frustrating. Can someone help me please?