Looping Through Comma Delimited String?
I'm wondering how I can loop through a comma delimited string in php?
my string: $string = "12499, 12498, 12497";
though the size will change depending on the query.
View Complete Forum Thread with Replies
Related Forum Messages:
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 !
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 !
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 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 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 !
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 !
Search String Delimited In Another String
I have a string (Website referrer). Example: http://www.google.com/search?q=MY STRING HERE&hl=tl&client=firefox-a&channel=s&rls=org.mozilla:en-US:official&hs=dXZ&start=30&sa=N I need to extract the keywords searched (example in the above case: "MY STRING HERE"). I think I need the string between "q=" and the next appearing "&". How can I do this?
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 !
Delete String After Comma
How would I truncate a string after a certain character? I don't know the index of that character. I think this is close, but I need to replace the 18 with the index of the comma in the variable mystring since I won't know where the user put in a comma. $mystring = "Hello I'm a string, and I have a comma."; $mystring = substr_replace($mystring , '', 18, -1); my result of echoling $mystring would be: Hello I'm a string"
View Replies !
Create Array From Comma String
I am currently learning from the book, Eric Rosebrock's "Creating interactive websites with PHP and web services" it is a great book, but I have a question. I have a string loaded from mysql that looks like this: PHP Code: $allowedfiletypes = '".jpg", ".tif", ".gif", ".png"' I want to turn this into an array but its not working, I'm trying something like: PHP Code: $allowedfiletypes = array($allowedfiletypes); so that if I print_r it it will output something like: [0] => .jpg [1] => .gif [2] => .png etc.
View Replies !
Count Comma Separated Values In String
PHP form that checks $name doesn't already exist and then inserts them into mySQL database. All works except for the $counted variable. $list is a string that looks something like this: 123,2536,2346,332,546. So in this instance $counted should have a value of 5 because there are 5 values in the string. But it gets inserted as 0. Cannot see what I am doing wrong. Code:
View Replies !
String Looping?
I am doing user authentication, and I need to find out if the username they chose starts with a number. What is the best way to go about that, is there anything built in to PHP4 to help?
View Replies !
Regular Expression That Will Split A String Into Several Parts With ',' (comma)
with a regular expression that will split a string into several parts with ',' (comma) as the separator, but NOT where the separator is enclosed in parentheses. For example, take the string "field1, CONCAT(field2,' ', field3) as field23, field4". I would like to be able to split this into the following: [0] field1 [1] CONCAT(field2,' ', field3) as field23 [2] field4
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 !
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 !
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 !
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 !
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:
View Replies !
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.
View Replies !
MySQL: Searching With Joins Or Delimited List
I'm trying to implement a solution where a given company can set a list of the coutries in which it has branches. My first thought is this: 'company' (id, co_name) 'location' (id, co_id, loc_code) And when the customer want to know if a company has a location in Belize: select c.co_name from company c left outer join location l on l.co_id = c.id where l.loc_code = 'BZ' My second thought is adding loc_code to company: Code:
View Replies !
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.
View Replies !
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?
View Replies !
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:
View Replies !
Exporting To CSV Contain Comma In It.
There are some text fields that I am exporting to CSV contain comma in it. And so when I open the csv file, everything is shifted. e.g. "Apple, Banana, Orange", "Excellent", "12345" gives me 5 columns instead of 3 in the csv: Apple Banana Orange Excellent 12345 How can I solve this problem?
View Replies !
Formatting With A Comma>
i inserted a salary into mysql with a text file but the command i said was to end field with comma, so i just made 750,000 like this in the txt file like this 750000. ok so how can i format my php to display it as the 750,000 and even better add a floating dollar sign would help as well Code:
View Replies !
Stripping Last Comma
When pulling flavors from a mySQL database, I want to strip the last comma from the array, however I'm not sure how to do this. The stripped down code is below with the comma I want stripped in bold red: $query2 = "SELECT flavors from chip_stan_flav"; $result2 = @mysql_query($query2) or Die("Couldn't execute query"); while ($row2 = mysql_fetch_array($result2)) { printf ("%s, ", $row2[flavors]); }
View Replies !
Sending Comma In Url
I have a page that has a drop down menu, when item is selected the request is send to info.php?item=selectedIndex. Everything works, however when I have selected value with a comma: "Comany, Inc" the url redirection does not work. Is there a function in php I should use to encode url, or commas are not allowed at all.
View Replies !
Only Split First Comma
i have to split a substring from a string how do it? my requirement is i have a variable $var =,1,4,7 out put should be like $var =1,4,7(split first comma from the value.
View Replies !
Remove First Comma
I have this string: ",c2=5,c3=6,c4=5......" Now I need to remove the first comma. I know it is simple, but I can find the right command.
View Replies !
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??
View Replies !
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?
View Replies !
|