Comma Delimited Csv Has Commas Inside Fields
I need to import a CSV file into a database daily. That operation in itself is simple enough but the trouble is that some fields are quoted because they have commas inside them. How do I handle this with my import script?
It would be much better if the CSV was created with all fields quoted or used a different delimited but sadly that is not an option.
View Complete Forum Thread with Replies
Related Forum Messages:
Statement With Comma Delimited Fields
I'm hacking into my vBulletin forum to use individuals current usernames, passwords, and membergroups to setup a premium portion of my site. I have the following query: PHP Code: $users = mysql_query("SELECT * FROM user WHERE username='$username' AND membergroupids=ཛྷ'"); With this query my login works for those who have signed up for the premium content on the forum. One problem is if the members join multiple user created member groups, they're membergroupids will be like 32,10,34. I need my query to find if they belong to 32 and if so allow them access. So, if they belong to 32,10,34 then they should be allowed to enter, but if they belong to 10,34 they should not.
View Replies !
Comma Delimited File
I am trying to read comma delimited rows of text. The problem is that some fields may be encapsulated in "" - particularly the text fields but not numeric fields. Is there a simple efficient way to parse the fields with comma but also strip off the "" encapsulating some of the fields with php? The problem is the "" encapsulation is optional. Some fields will have it, some won't.
View Replies !
Regular Expression For Comma-delimited Pairs
I have a textarea form field for inputting (or pasting) pairs of data. I need a regular expression pattern to validate each line for the following double quote number double quote comma double quote alpha string double quote carriage return The following comes close, but doesn't check for a carriage return at the end of each line: ^"([0-9]?)+"([,]s?"([A-Za-z0-9]+)")*$ For example the following would return true: "1","John" "2","Paul" "3","George" "4","Ringo"
View Replies !
Stripping Quotes Out Of A Comma Delimited File?
I have a flat file that I'm trying to stick into a MySQL database. One record per line, multiple fields per record, and many of them are null fields which are just double quotes without a space between. It's probably nothing really major for people who have done this before, but I'm a bit stumped. The file is comma delimited. Every field is surrounded by double quotes. I've done quite a bit of searching, on the php site and elsewhere, but I can't seem to get it to strip the quotes out so I can explode the file line by line to grab the fields.
View Replies !
Converting Comma Delimited Field Into Array
I have an array that goes into a MySQL database (via PHP). The only way I could find to insert them into the database was using implode. It goes into the database just great, comma separated (although I would like each to go into it's own field, but it's okay for now). The problem comes when I try to display it. Since it's comma delimited it display only the first item in the array. But there are multiple rows that should be displayed. I'm not sure how to explode it so that it will display them all. I've tried a loop but that just looped the first item in the field (the first part of the array). Code:
View Replies !
File Parsing Function For Tab Or Comma Delimited Files
I need a way to parse a file based on the delimitation of either tab or comma. Does anyone know the best way to do this that is the easiest? Also the file I am parsing might have a few empty strings between delimitation. I know about preg_split so if this is the only way could someone provide a link that explains regular expressions because i dont get it.
View Replies !
Create A Comma Delimited String That I Can Convert To An Array Using Explode();.
I am attempting to create a comma delimited string that I can convert to an array using explode();. I have the following code: Code: $cPath_new_a = tep_get_path($categories['categories_id']); $cPath_new_b = str_replace("cPath=", "", "$cPath_new_a"); $cPath_new_c = str_replace("_", "", "$cPath_new_b"); $cPath_new_d = substr("$cPath_new_c", -2, 2); $cPath_new_e = $cPath_new_d . ","; echo $cPath_new_e; This outputs 23,53, I need it to output 23,53 Using the substr($cPath_new_e, 0, -1); and/or rtrim() method to remove the last character for some reason removes all of the commas. Am I approaching this the right way?
View Replies !
Regular Expression :: Find Word Matches To Words In A Comma-delimited List
What's the *right* way to find word matches to words in a comma-delimited list. For example, if I have the following comma-delimited list of categories in a mysql db field: gameboy, nintendo, playstation and I do a search, I know I can use regexp to do something like: select * from categories where regexp 'gameboy,' Notice that I have the comma in there to match the whole word and the comma without matching part of a word (to prevent unwanted matches such as "play" to "playstation" or "game" to "gameboy"). The problem I'm running into is words that match that match the end of each word next to the comma (in this example, "boy" and "station"). What's the right way to match a word *exactly* using regexp *without* also matching *part* of a word.
View Replies !
Ignoring Commas In Individual Fields
I'm trying to develop a bullet proof CSV function that can ignore commas that are found in individual field data when parsing through a regular CSV file. Here's some of the code I'm trying right now: $file = fopen( $file_name, "r" ); $cnt = 0; while( !feof( $file )) { $line = fgetcsv( $file, 4096 ); $count = count( $line ); if( is_array( $line ) && $count > 0 ) { for( $i = 0; $i < $count ; $i++ ) { echo "<br>$line[$i] "; }}} fclose( $file );
View Replies !
Commas
Hi everyone, I would like to be able to insert commas into a number every three spots. Like if I had 1728, a comma would be insert between the 1 and 7. The number is random so I need to know if there is a works-for-all-numbers.
View Replies !
Commas In CSV
I have built this form in php and when I click on it, I am storing all the fields in .csv file. There is one field known as address which can contatin commas How can I make it so that when I open it in excel address remains below address as in the commas submitted for address in the form becomes part of the address.
View Replies !
Commas In #'s
ok i want to put commas in #'s like 3,000,000,000 ok. ok say the number is $player[gold] and say that it is 3000000 how do i add commas?
View Replies !
Tab-delimited File
I'm uploading tab-delimited file to a mysql database and the tab delimited file derives from an excel file. In these Excel cells some of them have a comma (,) in. Now when I save the excel file as tab delimited it now puts quotes around the values that have commas in the cell? how I can stop this happening?
View Replies !
Tab Delimited Problem?
Trying to load a tab-delimited file to a MySql database as per this thread with a few changes, but getting the error message: INSERT INTO test (first_name, last_name, department, dob) VALUES ('')Column count doesn't match value count at row 1 But I have the same amount of columns in my table as I do in my tab-delimited file being uploaded. I've also echoed out the query, but still don't understand. Can anyone please advise by looking at the code below – especially my INSERT into statement? Code:
View Replies !
Add Commas Between Names
i've got a script that pulls first name, last name, and suffix from a DB query and echos them only if they are not null. the names are cross-referenced by id number from two other tables. it displays the name pieces that are not null for each "job", and the jobs and names are determined by another id number for an individual issue page. an example of the output is here: Code:
View Replies !
Getting Rid Of Inverted Commas
If someone types 'Tom's Photos' into a input field i need a piece of code that removes the " ' " when the information is processed. Example Tom's PhotosScript Processes InformationScript Finds the " ' " in Tom'sScript Removes " ' " in Tom'sResult Is Toms.
View Replies !
Extracting Between Commas
I'm working with a database that would take me days to change to the correct format so I'm in need of a workaround. Is it possible to extract text that is in between two commas? I have a long string with multiple commas seperating the values, but it's only the 2nd line that I need for passing on in my code. The best way to explain is example: What's in the database: text123, WHAT I WANT, more stuff, another line of junk, both letters and #'s Can I create a function that turns a variable into "WHAT I WANT"? I know this is weird, but this database has 20,000+ entries and the "part number" I need is within one of the fields...and it's the only way to identify what I need.
View Replies !
Delete All Commas
How do I delete all commas from a string? I tried the explode/implode way, but it slows down the script a lot. I looked for an alternate function -- something like delete() like they have in pascal/delphi, but no luck. I have a number: 1,813,445 and I just want to remove the commas. Then use that number in an arithmetic equation, and then put the commas back in by using... number_format($str, 3) but when I use the above function, I get a number like 1,813,445.000. Is there a way I can receive the number without receiving the .000 and without using substr?
View Replies !
Encode Commas
I have data that i want to add to a field that has a comma in it. If I do a straight input, it will mess up the column count. How do i handle this.
View Replies !
Commas In Queries
I'm outputting data from my database. I'm using $_REQUEST to get a value to query my database e.g news.php?headline=new headline. I'm then searching for 'new headline' in my database and outputting the related information. My problem is that it isn't working for any headlines with commas in them eg. 'News Headline' todays news. It can't seem to find anything in the database if it has a comma in it. When I add to the database, I used addslashes(). I'm not striping the slashes...could this be why? But when I look in the database, there doesn't seem to be any slashes in there?
View Replies !
Commas In Links
I am creating a link and then it has text. I want a comma to display in the text but not sure how to do it. If I put the comma it will not show the rest of my text. Code:
View Replies !
Want Commas In Your Numbers?
Just made 2 functions for putting commas into your numbers. Also, these two functions with a little bit of syntax changes will work on TI-83 calculators, making it easier to awnser a question without looking like your using your calculator :). Code:
View Replies !
CSV File And Commas
I have a database that has a field where commas are used: PID PNAME PTYPE 011 hello small,medium,large In PTYPE above, commas are within the field. I would like to export this table to a csv format but how do I tell it to NOT read the commas within a field as the deliminator.
View Replies !
Delimiting A Non-delimited File
I have a text file, with addresses of business' that I would like to convert to a more useable format ie CSV. Currently there is no delimiting of the various address components. "A 1 AUTO SALES 1224 S BROADWAY ST WICHITA, KS 67211-3124 316-263-8748" "ABERLE FORD INC 1025 MAIN ST SABETHA, KS 66534-1893 913-284-3122" "ACTION AUTO RENTAL & SALES 1101 W 4TH AVE HUTCHINSON, KS 67501 316-662-3699" As you can see from the examples above the only consistent items are the state and the phone number, and the city is always followed by a comma. I am new to regex and the whole range of string handling functions and I am not sure where to start.
View Replies !
Preg_match And Delimited Strings
I have a string I'd like to have broken into parts using preg_match. I used a regular expression from the Perl FAQ (http://perlfaq.cpan.org/): push(@new, $+) while $text =~ m{ "([^"]*(?:.[^"]*)*)",? # groups the phrase inside the quotes | ([^,]+),? | , }gx; The idea is that it splits delimited strings respecting the quotes, for example... foo, bar, "foo, bar", bar would end up as -foo -bar -"foo, bar" -bar So obviously an explode wont work. I cant figure out how to convert that piece of perl above into preg_match. I've copied the string and escaped all the appropriate charecters however it still wont divide the string show above properly... $str = "foo, bar, "foo, bar", bar"; $re = ""([^"\]*(?:\.[^"\]*)*)",?| ([^,]+),?| ,"; if (preg_match($re, $str, $res)) { print_r($res); } I have other strings that need parsing too (including ones with a double encapsulator inside the string - eg. 'don''t touch that!'). But I'm saving those for later.
View Replies !
Tab Delimited Text File
I have a large tab delimited text file provided each day by my importer (about 8 MB). I would like to compare that file with my database by giving a column value. This .txt file resides at the local server. I have tried fgets(), but seems it cannot handle that large file. Because file() also not working.
View Replies !
Delimited Text Format
I am trying to export data from a DB in a "delimited text format" with PHP and a MySQL DB. I am able to create CSV file and a tab delimted file by printing "/t" after each item. however this apparantly isn't a "delimited text format". tell me how I can do this?
View Replies !
Dots Versus Commas
What is the difference between using dots or commas. I got some help with a script I'm using and the person used dots where I originally used commas. The script is working fine, but I'm trying to learn to write good code instead of just code that works. If there's something bad about using the dots, I'd like to know how to fix my script so it's right.
View Replies !
Change All Commas To A Space
The following works fine for replacing "normal" words in a MySQL table: UPDATE tablename SET fieldname=(REPLACE (fieldname, 'oldword','newword')); However, I have a situation where I need to change every comma that appears as text in a particular field to a space. How would I do that?
View Replies !
Adding Numbers With Commas?
<? $var1 = ཆ,000' $var2 = Ɖ.59' $sum = $var1 + $var2; echo $sum; ?> I'm getting "13.59" I'm obviously missing something pertinent to adding numbers with commas. Any help?
View Replies !
Script/Code For Commas
If i want all numbers to contain commas like 123,456,789 how would i do that right now they are 123456789 and i want it so they all contain them how would i do this? btw the numbers change automatically on there own.
View Replies !
Commas In Numerical Values
I want to know if there's a way to include commas in numerical values in a database. I have a lot of integer (INT) rows but I cannot include commas, so instead of 10,000 I can only enter 10000. The reason I want this is because in the output, I want all numbers to have commas. Is there any way around this?
View Replies !
Seperate String By Commas
I have a string that I want to create into multiple hperlinks where it is seperate by commas. Ex: $names = "john, dave"; Now I'm trying to make URLs from each name: $splitdata = explode(',', $names); echo "<br><a href="http://www.mydomain.com/search.php?name=$splitdata[0]">$splitdata[0]</a>, <a href="http://www.mydomain.com/search.php?name=$splitdata[1]">$splitdata[1]</a>"; Obviously this is the wrong way to go. Because there are instances where the variable has more than two names, and I'm not counting the instances in the above example.
View Replies !
Create A Delimited Text Array
How can I create a delimited text file to work with this script. I would like to put this first part in a text file and load it into an array so the php script can parse it. Code:
View Replies !
Tab Delimited Txt File To Php Html Table
Wouldn't you know that when I finally find a tutorial using Google that does exactly what I want, the code doesn't run when I use it ... However, when it gets to this line, for ($i=0; $i<td>$line[0]</td>, it chokes on one of the '>'. Since my php skills are very basic, and in no way include arrays, can someone assist me with this? If it's easier to do it differently, what I'd like to do is create a table in Excel/Access, export it to the server (to a tab-delimted text file, since I'll be using commas in my table cells), and have it display in an HTML table. If I can't figure this out, I'm tempted to just export to HTML from one or the other program (not sure quite yet which I would use), so ...
View Replies !
Reading Tab Delimited File Into Database
I have a .tab file that I need to write to the database. I've read it in, but for some reason it's not reading correctly. I'm truncating the complete database and then reloading it with whatever is in the tab file. I keep getting an error when trying to run my current code which is: Code:
View Replies !
Parsing A Delimited, Encapsulated String
i've used fgetscv() before. It has some kind of built in logic to determine when a comma is inside a field versus when it's used as a delimiter and works quite well. i would like to put together some kind of preg_match expression that can take a delimited, encapsulated list of values and return all the elements. can some preg pro help me develop this expression?
View Replies !
Upload Text Delimited Field
I'm trying to use an upload file form: Code: <input name="upload" type="file"> I want to upload a comma delimited text file that is structured like: ID,Date,Team1,Team1Name,Team1Score,Team2,Team2Name,Team2Score,Detail What I'd like to do is have some PHP (and mySQL) that'd take that comma delimited file and insert it into the database, and if the ID in the file is already in the DB to overwrite it.
View Replies !
Inserting Proper Commas Into An Integer
I've looked and looked, and I can't find anything about this, and it's driving me nuts! All I want to do is insert a comma into a long number (when applicable) to make the display look nicer. This script is counting pageviews on my site, so it'll be a large ugly number in a few days. For example, instead of displaying: 1876235 I would want it to display 1,876,235 The integer could be any size (potentially), but I don't see any need to worry about numbers beyond 8 digits. Any suggestions?
View Replies !
Regular Expression, Exclude Commas
Greetings all. I'm a newbie, desperate to learn, and I've searched here and Google for such things as "PHP regular expression comma" and variations on that theme, but I haven't been able to figure out what I'm doing wrong, though I've visted several sites and tutorials dealing with regular expressions. I've got a form on my bosses' Web site where a customer can enter a price range and get a list of our "stuff" that falls within that price range. I'd like to set something up so that if they enter letters or commas or anything other than numerals in the price range form fields, they'll be gently encouraged to go back and do it right. :) This is what I've got for the time being: if (!eregi('^[0-9]', $pricemin) ¦¦!eregi('^[0-9]', $pricemax)) { echo '<P>You have not entered a valid price range. ' echo 'Be sure to enter only numbers, and no letters or punctuation marks, when searching for a price range. ' echo 'Click the Back button on your browser to search again.' exit; } This works, insofar as if someone types "blah" in the pricemin or the pricemax form field, they'll get the message. But if some well meaning person types "50,000" or "$50,000" instead of "50000" in there, they currently get a MySQL error. I've got a note telling people not to use letters or punctuation, but you know how people are. All the tutorials I've seen talk about including or excluding different characters based on different criteria, but everything I've tried to put a comma in there has failed and/or messed up the query somehow. What am I missing?
View Replies !
Stripping Commas From Real Numbers
I have an HTML form in a PHP script which queries the user for a dollar amount of sales. If a user enters "1,000,000" rather than "1000000" for 1 million, PHP (or MySQL?) treats the commas as a decimal and "1" is entered in the database. A simple work-around is to simply advise the user "Please enter numbers only, no commas or $'s" but this seems awkward. Is there a built in function or another easy way to have commas and currency signs stripped out of form-entered data?
View Replies !
Stop The Commas!!! ( Or Knowing When You're At The End Of An Array )
I am looking for a good way to know when I am at the end of a comma-separated list of array values. My code is simple (as well as I'm sure is the solution I'm looking for; and YES I've search the php manual!! Arrggghh! ) Anyway the code goes like this: ... <td><select name="pref_cities[]" multiple size="6"> <option>Nagpur</option> <option>Mumbai</option> <option>Bangalore</option> <option>Chennai</option> <option>Kolkatta</option> </select></td> ... <?php $cities = $_POST['pref_cities']; foreach ($cities as $city) { echo $city . ", "; } ?> I want to know when I'm at the last element in $cities[] so that I can output a period (.) instead of a comma (,).
View Replies !
Comparing Arrays - Separated By Commas
I have a MySQL database which has a load of musicians on it. Each musician has a field that stores their influences, which are separated by commas, e.g: The Beatles, The Beach Boys, Kiss etc etc. Now, what I would like to do is start with the influences of one musician, and then compare it to all the others to find the closest matches - i.e find the musicians that have (say) more than three influences i common. This would then allow you to see which musicians had the most influences in common with the primary one, the one you started with. Here's what I have in mind, it seems a little laborious - load the influences of the primary musician into an array using the explode command. Then step through each of the other musicians in a loop, each time putting their influences in to an array and checking to see how many matches there are between the two arrays. Whenever there is at least one match, the name of the musician and the number of matches would be put into a third array. This array would then be sorted at the end, so that the musicians with the most matches would be at the top, and the script could then display them. This would probably work, but if looking at several hundred or several thousand musicians, it would surely be quite slow - is there a better way? I don't particularly want to use a separate, normalised table at this point - I know it would be the quickest way but it would involve a lot of restructuring for me. I know that PHP has several clever inbuilt routines that might do this job for me, so if anyone can suggest anything I'd appreciate it.
View Replies !
Adding Commas To Large Numbers
I have a search that when you search it shows how many results you are being shown and usually the number is between 100,000 and a 1,000,000 how can i add commas to a number for example: 989725?
View Replies !
|