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 Complete Forum Thread with Replies
Related Forum Messages:
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 !
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 !
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 !
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 !
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 !
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 !
Parsing Htm Files As From Within A File
I am compressing the .htm files served from a website using these lines in my (Apache) htaccess: AddHandler compress .htm Action compress /php/compress.php The compress.php file is simple (described here): <?php ob_start("ob_gzhandler"); $file = $_SERVER["PATH_TRANSLATED"]; readfile($file); ?> Before I implemented this php compression, I had the server parse .htm files as php using AddType application/x-httpd-php .htm in htaccess. But now that the Handler is functioning (and it works great), embedded php in my .htm files is no longer executed. Code:
View Replies !
Comma Delineated Files
I have an file whose contents are as follows: "test","com,ma","food" $file_contents = array('"test"','"com,ma"','"food"'); Doing explode(',',$file_contents) wouldn't be sufficient because the resultant array would have four entries - not three - and would instead read like this: $file_contents = array('"test"','"com','ma"','"food"');
View Replies !
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.
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 !
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 !
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 !
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 !
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 !
Function In PHP To Create Files Such As A Php File Or Txt File?
I am currently creating a file manager to add/edit/delete files and folders, etc but i was wondering if there is a function in PHP to create files such as a php file or txt file? All i want is a function that will allow you to create a file from the name you give! Is this possible? I have seen a script called Genesis but the problem is that it is Perl! and i dont have a clue about Perl!
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 !
Uploading Comma Del File To Database
I have gotten this to work on my home setup and my personal setup at work. But cannot get it to work on the live server at work. I am trying to setup a inventory system for about 5000 PC,Printers in about 5 diffrent locations. (a multi site hospital) The reason I cannot use phpmy inventory is because of the complex information needed to make it useful. But I could write a long thread about that. My first step I am working on is a simple upload text file that inserts the info into a database table with only two fields. So here is the info, Code:
View Replies !
Parsing Files
I encountered the concept of templates and parsing files. For example: sometimes when you search a site, and when you visit links that the engine returned you found your query highlighted inside the text. Very nice. They parsed the file you requested and put some nice formatting around all occurences of your querystring. I would like to apply it different, more in a sense of: you enter a URL in the address bar, and this file is parsed before it is shown to you. An application would be:all e-mail addresses inside the file are replaced by mailto:hyperlinksall static hyperlinks inside the file are replaced by real hyperlinks etc. A normal php-file at my site looks like: - php-include (html: header) - text: html formatted - php-include (html: footer) How can I achieve that when this file is loaded all occurences of some kind (stored in an array containing all needles) are handled in some way to show appropriate hyperlink-formatting before it is presented to the user. (much like a dictionary: words in the text can be references and are explained elsewhere). It is required that the text stays the same and the file can be loaded stand-alone (without querystrings).
View Replies !
Parsing CSV Files
I have a function to parse a csv file and insert into a table in my database. This works great so long as its a very simple file. Code:
View Replies !
Parsing With XML Files
I need to find all occurances of <root contentId=" in this xml file and then be able to access the value of the content id via an array as needed. Code:
View Replies !
Parsing Xml Files
I have been stuck on this issue for roughly 3-4 days. Basically I am querying amazon.com ecs system to get data from them in xml format (the only format they provide). What I am trying to do is this. * Make a request to there system * Set all the values in an array * make a second request * Add the values into the existing array * Continue that cycle until I am done * form a nice table using the array. I have tried everything. Expat, Simple XML, XML classes, and nothing is working. Can anyone point me in the right direction for this type of issue?
View Replies !
PHP Parsing Webalizer Files?
I have currently over 50 domains and I'm just checking the stats on daily base for about 3-4 domains. However I'd like to know to overall stats. I thought that maybe once a day a cron starts lynx which calls a php script to parse the newly generated webalizer files and enters relevant data into mysql. with relevant data I mean the top referers, the number of uniques and a few more items. I should be able to somewhoe configure what domains shall be used and where webalizer files for those domains can be found. Anyone ever seen such a php script or would a new develepoment be necessary?
View Replies !
Parsing Large XML Files
How can I parse a large XML file that is to large for memory? I am currently using php 5.0.3 and the libxml parser, I would like to read it incrementally from a file, but the parser gets the entire contents from as String?
View Replies !
Text Parsing Files (rtf)
I want to take a bunch of text files (rtf), read them in and dump the contents in a database. The files are effectively a flat file database, with I suspect some fairly intricate programming needed to process the files. Unfortunately, they are laid out for human readability, not data...
View Replies !
Parsing XML Data Files In Php
I have written a php routine which parses a xml file and puts the data in the database the script goes into a certain folder looks for .xml files and then parses them one by one and does the database entry. I have written this code so far however I am not able to get the right sql queries . Each xml file will have one order id and several images associated with that orderid and there maybe several such xml files. Now for each orderid I have to insert the order id and imagenames and other data into the database. Code:
View Replies !
Parsing Text Files
I'm trying to work on a website for a sports league, which inputs stats from Madden NFL 2008. I've looked up as much information as I can about parsing TXT files, but I'm still confused as to how to approach this. Specifically, I want to read the data from each section (general info, game settings, scoring info, game stats, home passing stats, home rushing stats, etc.), and enter them into separate tables. Code:
View Replies !
Parsing Large Files
Does anyone have a suggestion for parsing large files line by line without loading the entire file into memory first? I don't want to use file() because the files I'm working with may be multi-gigabyte so loading them into arrays would be pretty memory intensive. In Perl, I can do: "while($line=<HANDLE>){do something with $line}".
View Replies !
Parsing Unicode Ini Files
i am trying to parse .ini language files for different languages. i am using parse_ini_file() which succeeds in parsing english language only(i can't parse arabic language) can anyone help with a modified version that parses arabic and other languages as well?
View Replies !
Parsing Html Files
I have a new server and the company doesn't seem to understand what I need. I need to run php code on a html page. I've created an htaccess file and tried each of the following directives inside of it... AddType application/x-httpd-php htm html AddHandler server-parsed .html .htm AddType x-mapp-php4 .html .htm (they were tried one at a time) The script output still does not appear. Is there a feature, funtion or option that would prevent the htaccess file from not working? Is there something in Apache that needs to be configured? I know this possible because it worked with my old hosting company several times. I don't know how and they don't offer support for servers other than their own. I need the page extention to be .html not .php so changing the pages to .php is a non-option. What needs to happen in order to parse html files as php?
View Replies !
Html Files Sent To The Php Parser For Parsing
I want all my html files sent to the php parser for parsing. I tried to put up an .htaccess file with just this in it: AddType application/x-php .htm Action application/x-php /usr/bin/php AddType application/x-php .html Action application/x-php /usr/bin/php.
View Replies !
Parsing HTML Files On Local Computer
I would like to be able to open and read HTML files that are on my local (client) computer and then parse them to extract some specific information they contain. I've been looking here and reading my PHP books, but it appears to me that PHP only opens files on the server or URLs. It think that makes sense to me. Is there an alternative?
View Replies !
Parsing Some Text Files That Have All The Spacing Between Words Doubled.
I am parsing some text files that have all the spacing between words doubled. The space between characters is one instead of zero, and the space between words is two instead of one. I am trying to create a regular expression that replaces the single space between the characters in the words with no space. Something like preg_replace('/.s.','',$string).
View Replies !
Preg_Replace $1 <-- Function Parsing
you know in preg_replace, you can use "(.+?)" and then in the next param, use "$1" well i need to parse that "$1" variable into a function... see right now it uses it inside the quotes. but when i take it outside the quotes it has errors. it is currently: "etc $1 etc" i tried: "etc " . name($1) . " etc" but that creates an error, i tried the function inside the quotes. nothing. any ideas?
View Replies !
XML Parsing And Function Return Values
I am attempting to create a script that will search through a directory tree, find any xml files, and update an index (in a MySQL DB) whenever the script finds a file that hasn't been previously indexed. My problem is with the XML parse function (something I am not too familar with). Each xml file has a pair of ID tags that contain a unique number. I want the "idCheck" function to return a true/false on whether it finds the number already listed in the DB, but the extra functions involved in parsing have me confused as to how best to do this. How would I get the return value from the "contents" func back to the script that calls "idCheck." Code:
View Replies !
String Parsing Function Like In Java
I am new to php, but is there a string parsing function like in java which allow you one big string in to many smaller stings. In java there are 2 ways tokens and string functions. Are there types of things in PhP.
View Replies !
XML Parsing - Use A String Function And Remove The Excess Data
When I run... foreach($batch_1_data as $book) { echo "BOOK ISBN: "; print_r($book->ASIN); echo "<br>"; } ...I get... Code: BOOK ISBN: SimpleXMLElement Object ( [0] => 0007149670 ) BOOK ISBN: SimpleXMLElement Object ( [0] => 0023963603 ) BOOK ISBN: SimpleXMLElement Object ( [0] => 0028624491 ) BOOK ISBN: SimpleXMLElement Object ( [0] => 002863716X ) BOOK ISBN: SimpleXMLElement Object ( [0] => 0020423500 ) BOOK ISBN: SimpleXMLElement Object ( [0] => 0015678326 ) BOOK ISBN: SimpleXMLElement Object ( [0] => 0006547583 ) BOOK ISBN: SimpleXMLElement Object ( [0] => 0006547567 ) BOOK ISBN: SimpleXMLElement Object ( [0] => 0006478964 ) BOOK ISBN: SimpleXMLElement Object ( [0] => 0023963700 ) and I'm trying to get... Code: BOOK ISBN: 0007149670 BOOK ISBN: 0023963603 BOOK ISBN: 0028624491 BOOK ISBN: 002863716X BOOK ISBN: 0020423500 BOOK ISBN: 0015678326 BOOK ISBN: 0006547583 BOOK ISBN: 0006547567 BOOK ISBN: 0006478964 BOOK ISBN: 0023963700 I've been playing around with this for an hour or so and was wondering how this is supposed to be done using Simple XML. I know I can just use a string function and remove the excess data, but it's not the best way to do this.
View Replies !
|