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
See Related Forum Messages: Follow the Links Below to View Complete Thread
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.
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"
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.
Easy Comma-delimited List To Dropdown Box Converter
I was working on a simple converter when I realized that by not setting the id param of the option tag, it wasn't going to send the value of the dropdown box to my php script. I had this to start with: Code:
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.
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.
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?
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:
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.
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?
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?
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?
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 (,).
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?
Strip Out Commas And Characters In A Text Box
I have a form that the user can enter a number in the text field and a calculation is then preformed with PHP when the form is submitted. $amount = $_POST['amount']; <input type="text" name="amount" size="20" value=""> Any way to strip out commas and any characters that may be entered. I would like an entry like $5000, 5000, 5,000 and $5,000 all to be passed on to the PHP script as 5000. The way it is now the php math script treats 5,000 as a 5 and $5000 as a 0.
Change Alternate Commas To Semi Colons...
With a string of authors such as: I would like to write a function to change every other comma into a semi colon (thereby defining where one name ends and the next begins). I could do it by writing a complex (and slow) procedure - but is there a quick way of doing it using regular expressions, for example?
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.
Exploding Tab Delimited Line
I'm trying to create an array from a tab delimited line of text. I've tried explode('/t',$line); but doesn't seem to work. What am I doing wrong?
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.
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:
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 ...
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:
Match Input Value With Values In A Delimited File
I'm very very new to php. I need your help. I have a text file which is ~ delimited. Each line has a name and link. I want to check if the link is similar to my input and if it is then return the name.
Importing To DB From Pipe Delimited Text File
I am trying to make a PHP script that will import data from a pipe delimited text file in to a database. The problem I am having is that the fields have long descriptions in them and there are multiple line breaks for paragraphs. They contain HTML codes as well (<B>). The multiple line breaks are causing it to import the data strange, putting data in the wrong fields and totally missing some data as well. Here is what the text file Code:
Multiple Table Insert From Tab Delimited File
I have a page I'm coding for batch updates from a tab delimited file. Each row has data that has to be checked against and inserted/updated on different tables in my mySQL database. How would I go about parsing through the tab delimited file and then storing data between the tabs in order to insert individually into separate tables?? Here's what I have so far... $contents = file('/myfile.txt'); for ($i=0; $i<sizeof($contents); $i++) { $line = trim($contents[$i]); $arr = explode(" ", $line); $line[$i] = array('ID' => $arr[0], 'Record_Type' => $arr[1], 'First_Name' => $arr[2], 'MI' => $arr[3], 'Last_Name' => $arr[4], 'Firm' => $arr[5], 'Address' => $arr[6], 'type' => rtrim($arr[13])); I need to take the different columns.. ID, Record_Type, etc. and update different tables with each value where the IDs match.
Comma Seperator
I have numbers retrieved from database which is quite big. Is it possible to give a comma seperator in the sql query or otherwise how can I format with a thousand comma separator?
Deleting Last Comma
The code below displays pet names like so: Fido, Bowser, Kittycat, Spot, and I want to delete only the last comma. I tried 'substr' and 'rtrim' and both of those delete the space and comma between each name, not just the last name as I'd like, so I end up with: Fido,Bowser,Kittycat,Spot, How would I delete only the last comma, so that it is this instead? Fido, Bowser, Kittycat, Spot Even with trim and substr, I end up with:
Comma Separated Values
What i've done is when the user enters the client list separated by commas..... this works, but I need to know how to warn the user when they have enter the client list with no commas. Is there some sort of function which does this or is it a regular expression thing??
Seperating An Array With A Comma
I'm trying to seperate the output of an array with a comma. I can't figure out how to eliminate the last comma. Here is my code: $result = mysql_query($query,$connection) or die (mysql_error()); $fw = fopen("/var/www/html/ecast/windex/graph.html","w"); fwrite($fw, "/ "); if ($new_rows = mysql_fetch_array($result)){ do{ fwrite($fw, $new_rows[0]); fwrite($fw, ", "); }while($new_rows = mysql_fetch_array($result)); } fwrite($fw, " /"); fclose($fw); ?> Output: / 85, 86, 87, 89, / How can I eliminate that last comma?
Removing A Comma From The End Of An Array
I am reading a file into an array using this: $listFile = "add2db.txt"; if (!($fp = fopen($listFile, "r"))) exit("Unable to open the input file, $listFile."); $buffer = fread($fp, filesize($listFile)); fclose($fp); The very last character in that $listFile will always be a comma. What I need to do is remove that last comma (and only that comma) from $buffer before I can continue on. What do I need to do to accomplish this?
How To Instert Comma Into Number?
I am having users submit large numbers into a form, and when those values are returned to them later I want to have the commas in the correct places. ie. 123456.00 changes to 123,456.00. Is there a function that does this conversion? Also, how would I ensure that the number is always displayed with 2 decimal places, ie. 123 changes to 123.00, but 123.00 remains 123.00.
Importing A Flat Pipe Delimited File Into A MySQL Data Table
I have done this in perl but eeew I don't want to use perl anymore. I want to be able to take a flat file that looks like this: mbriones@...|Marian|Briones bobsmith@...|Bob|Smith janedoe@...|Jane|Doe (etc) The table has more than 3 fields, so I'd want to process the flat file and then do an INSERT into mailinglist SET field=$value for each line. Does someone have a nice way for me to do this? The flat file will be uploaded to the server via a form (copy) and then be processed.
Re Comma Separated List - Another Question
I can do the match perfectly but what i also need to do is create a third list of comma separated values that are in both eg: List 1 => 1,2,3,4,5,6,7,8,11 List 2 => 1,3,4,5,6,7,10,23 Therefore List 3 => 1,3,4,5,6,7 How do I populate this third list - I'm really stuck ....
Breaking Up A Comma Seperated List
i have a list seperated by commas: 1. 3. 5. 7. 9 actually is a varible $members ="1, 3, 5, 7, 9"; what would be the best way to break that up to insert the values into a table in a loop.
Comma Seperated List Comparison
is it possible to compare acomma separated list aginst another eg comma list 1 => 1,2,3,4,5 comma list 2 => 3,5 can you check that 3 is in both, and 5 is in both, therfore they match? the comparison is to check that if product a who supplies products 1,2,3,4,5 can be used instead of product b who supplies 3,5 as product a already supplies them
Exploding Comma Separated In Array
I'm looking to explode the comma separated values in an array like this: Array ( => 10811 [1] => 7527,7556 ) and then add the exploded value as a new key in the array...like this: Array ( => 10811 [1] => 7527 [2] => 7556 )
Seperator Instead Of A Comma For Listed Items In DB?
I'm making a recipe database, and need to have DB fields in mySQL that will have lists of values that would get sent to an array to be worked on. I anticipate that at times a comma will need to be used in the value itself. So, what's a commonly used symbol or something that people tend to use as a separator of a list that would then be used in the split() function to send the elements into an array?
How To Check If It's The Last Result And Remove Comma
I am wondering if anyone could help. I have a loop that displays my results and places a comma after each. The problem is that when the last result is displayed, it shows the comma. Example: for loop{ echo $row['test'].', '; } displays... test1, test2, test3, Notice after test3, there is still a comma? How do I remove it and have it display... test1, test2, test3
Comma Separated Text Files
A client has requested that I make a php app which takes an uploaded image, reads the values and enters them into a database. I've made the upload script which works fine, and the script which enters the values into the database, the only thing left now is how do I make PHP read the file and extract the values? The file is a text file, each field comma separated.
How To Remove Last Comma From A Multiple List?
I have a multiple select list in my site where the values are inserted in a database table, in a column named available_country. I enter these values in the db separated with comma. I don't know however how to remove the last comma so it will be something like this: USA, Europe, Asia and not: USA, Europe, Asia, Here's what I tried but it didn't worked: ...
Looping Thru Array And Creating Comma Sep String
I'm trying to loop through the elements of an array and create a comma separated string of the values, and then trim off the last comma. Here's the code I have which only displays the last element of the array in the string: PHP Code:
Comma Separated List In MySQL Field
say I have a list of categories in a field, and a page that is supposed to pull from the db based on a category. Is there any way I can do a query where it searches the contents of that field for the category in question? like SELECT FROM table WHERE category = $category but have it search the category field (the comma separated list for each entry) for the $category var
Seperate Links From Comma Seperated Value In A Databse
I have a value which is $keywords in my database The key words are separated by commas, like: fun, funny, exciting, weird I want to make each of those keywords link to "link.php" I can only get them all to be one link, how would I make them each into seperate links.
My Data Contains Commas And Pipes "¦"
I have some raw data that I was planning to insert into a flat file and then upload/insert into my mySQL DB. However the data contains commas and pipes "¦". I usually use the ¦ as my delimiter. Before I upload the data I wanted to remove dupes which happen to be text/blob fields. I usually do this in access. I thought I could get around this by using quotes as a text qualifier. It didn't seem to work. My other method I usually try is to use some combination of characters like <¦¦> as a delimeter. However Access only allows one character as a delimeter and phpmyadmin only allows two characters as the delimeter.
|