Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





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 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 !
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 !
Stripping Double Quotes And Replacing With Single Quotes
I have a problem I had trouble finding any existing threads on in the forum.

I have tried learning more about str_replace() but have had trouble with implimentation.

Here is what is happening. I am adding text to a variable called $content that looks like this:

Hi everyone. This is text I made up. I think it was Larry that said, "Love is a battlefield". But I think it was Benitar.

Now I want to replace those " " in there with ' ' (single quotes.)

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 !
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 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 !
Reading Excel To MySql Or Comma Delimited ...
right direction on how to deal with an xls
flie.

but the only other file I have to work
with is pdf.

I'm not sure, is xls the better of two evils?


View Replies !
Set An Array = To A Comma Delimited String Of Strings
is there anyway I can set an array = to a comma delimited string of strings and then loop through each of those manipulating the string. help me with the basic code for setting up the array and looping through it.

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 !
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:

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 !
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 !
Stripping The Quotes
I have a form where I prepopulate values from my db. Something like this: PHP Code:

echo '<input type="text" name="subject" value="'.$myValue.'">'

It works fine until the string has quotes, then iut just cuts off at the quote, Example:

$myValue = 'This is my "NICE" string'

In the form I'll only see This is my Not sure how to resolve it without stripping the quotes.

View Replies !
Stripping Quotes From Form Input.
Is there a (better,quicker,easier) way of stripping anything other than text, and numbers without using an if statement to catch errors, and have them re-enter the info? I'd rather just strip them all together.

Something like.. if I want to stip out anything other then the alphabet, and 1-9, so I don't have entries that look like this.. Quote: ..%blah''''""""";blah!!!@@@~``

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 !
Extracting Delimited Text From A File
I want to extract several lines from an html file that begin with pattern1 and end with pattern2 and ignore everything before pattern1 and after pattern2.

View Replies !
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.

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 !
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 A File And Stripping Things From The File Name
Me again with a variation on the earlier problem.

I need to strip illegal characters out of an uploaded photo now. I am
trying this without results:

$photofile=ereg_replace("[^[:alnum:]+$]", "", $_POST['photo']);.....

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 !
Quotes In File Names
I am developing a php web browser application. But i have a problem. I am listing with opendir but there are a lot of files with quotes in their names. example: News Letter for "ebal" today.html When i browsing the files the listing doesn't show me the full name of my files, because of the quotes in the filename.

View Replies !
Escaping Single Quotes, Double Quotes, And Semicolons With STR_REPLACE()
i have this error code unexpected T STRING on this line:

str_replace(addslashes('onmouseover="showImg('name', 'tabla_novedades2', 's_asc.png', 'img1');"'), addslashes('onmouseover="showImg('name', 'tabla_novedades2', 's_desc.png', 'img1');"'), $td_name);

i tried escaping slashes with the addslashes function but obviously this did not work
there is a ";" in the string so i know that is causing the error

I am replacing this string:
'onmouseover="showImg('name', 'tabla_novedades2', 's_asc.png', 'img1');"

with this string:
'onmouseover="showImg('name', 'tabla_novedades2', 's_desc.png', 'img1');"

how do I do this with no errors with the str_replace function??

View Replies !
Reading Left And Right Quotes From File.
I am trying to read in the content of a file with the php file() function and when I do then all the left and right quotes “” and ‘’ are conveted to odd characters.

so this:

Downtown is ‘sole focus’

becomes this:

Downtown is Ôsole focusÕ&#65533;&#65533;

I read the file like this

$array = file($_FILES['tmp_name']);
$headline = $array[0];
echo $headline;

View Replies !
Single Quotes And File Uploads
It appears that $_FILES['userfile']['name'] does not support single quotes. Whenever I try to upload a file with a single quote it will truncate everything before the quote in the name.

I've been doing some testing but it may actually be the file input type not liking the single quote. Code:

View Replies !
Practical Reason For Single Quotes Vs Double Quotes
I've always wondered why - or even if there's a difference - for using double quotes vs single quotes in php.

My code typically ends up with a mish-mash of both - sometimes I'll use:

$tomorMonth = date('n', $tomorrow); on one line, and then,
$arrMonth = $_POST['arrive_month']; on another line (or lines)

Both seem to work okay - I don't seem to be throwing any errors - but my question here lies in the interest of getting the "best practices" usage straight so I can start implementing single or doubles as appropriate.

So... when SHOULD someone use singles over doubles ... or does it make any difference to php at all?

View Replies !
Single Quotes And Double Quotes Showing As ? On Web Page
I have an issue with quotes showing as question marks on my webpage. I am sure its a UTF-8 related issue, but some of the facts surrounding the issue confuse me. The database is MySQL and stores the text as UTF-8. The PHP script simply takes the data from the database to a string: $desc = $info['description'];

And the text itself, is in a HTML string in the database as:

<P class=MsoNormal style=MARGIN: 0in 0in 0pt>The Golfers will enjoy their favorite sport on the Golf course only 5 min drive from “The Vineyards”.</P>

I am pretty sure that the original source was MS Word, and that the double quotes, in this example, are the special quotes from Word and not the ASCII quotes. When the webpage displays, it displays with the Unicode encoding. So, database is UTF-8, assignment in PHP is simple assignment without any form of stripping, tag removal etc.  And encoding on webpage is Unicode.  So can anyone suggest why they arent being displayed?

In the above example, the latter part of the text shows as ?The Vineyards?
It seems to apply to double quotes for sure, but also to some single quotes, as I have other text that displays as it?s instead of it's.

View Replies !
Magic Quotes -add Slashes To Any Single Or Double Quotes.
I check my phpinfo page and according to it, magic_quotes_gpc is set to ON. But when I enter this on a form input field (name="comment"): He's cool and post that on the next page: $_POST['comment'] and print. I got: He's cool . I thought I was supposed to get: He's cool since magic_quotes_gpc is enabled and it's supposed to add slashes to any single or double quotes. Why isn't it adding the slash in this case?

View Replies !
Escaping Quotes - Write To A Text File
I'm creating a form and one of the fields in the form is a big text area that I want to use to write to a text file. This works fine but the problem is all the single quotes are get escaped with slashes. I want to write to the text file with out the quotes getting escaped, I've tried htmlentities but that doesn't seem to work. Here is a snippet of the code.

$Desc_file = date("dmYHis");
$Desc_new = htmlentities($desc, ENT_QUOTES);
$filePath = "/public_html/nsite/info";
$WriteToFile = fopen("$filePath/$Desc_file","w+");
fwrite ($WriteToFile, $Desc_new);
fclose ($WriteToFile); .

View Replies !
Convert The &rsquo; Quotes To ' Quotes When I Get The Strings From The Db ?
in the db are a lot of short text strings that have been copied and pasted from a Word document - any time there's a single quote it's a &rsquo; and not a standard single quote. this is causing problems when i compare it to user input that contains standard single quotes. when i compare the two strings they are not equal . is there any way i can convert the &rsquo; quotes to ' quotes when i get the strings from the db ?

View Replies !
Replacing Double Quotes With Single Quotes
I'm looking for a way to scan a block of text and replace all the
double quotes (") with single quotes (').

I'm using PHP to pull text out of a mySQL table and then feed the text
into a javascript function called by onClick. The problem is that the
text may contain single or double quotes, which screws up the
javascript. I eliminated the single quote problem by running the text
through addslashes, but the double quotes are a problem. Code:

View Replies !
Alternative To Addslashes For Quotes And Double Quotes?
I have a website, where users go and enter text descriptions about items, whenever anybody uses a "(double quote) it throws everything for a loop, when storing it in my db I am using addslashes, is there something that needs to be done when it is retrieved from the db? Is there another function that should be used besides or with addslashes.

View Replies !
Removing Quotes From An Array, String Or Txt File See Code
I'm trying to process a tab delimited file where each line in the file
has around 12 tab delimited elements. My problem is the elements are
surrounded by "quotes" and I need the script to remove the quotes
after loading the file to the $addresses variable.
The quotes need to be removed somewhere within the code below or by
processing the file before loading.

//read in the name and address lines from the txt file
//each line becomes an element in the array
$addresses= file("download.txt");

//count the number of address lines in the array
$number_of_addresses = count($addresses);
if ($number_of_addresses == 0)
{
echo "No addresses to process";
}

echo "<table>";

for($i=1; $i<$number_of_addresses; $i++)
{
//split each line or row
$line = explode(" ",$addresses[$i]);

View Replies !
Double Quotes & Single Quotes
I have a web page with four input boxes. If a user types in text with either single or double quotes the insert fails.

I have looked into solutions and there seems to be some disagreement on the best method.

Some people say turn on magic quotes while others say not to, or use addslashes and stripslashes and again some say not to.

What about an mssql version of mysql_real_escape_string and mysql_escape_string??

What is the correct method? How do I overcome?

View Replies !
Single Quotes, Double Quotes And "undefined Index"
I am trying to write clean code but keep having trouble deciding
when to quote an array index and when not to.

sometimes when I quote an array index inside of double quotes I
get an error about enased whitespace (to my best memory)

AT other times I get an undefined index notice as below:

Notice: Undefined index: last_reminder_id in...

the 2nd line (which wraps to the 3rd in this posting
is the one listed in the error message:

$sql = "SELECT * from notes
where recall_date &#390;' and recall_date <= '$now' and id >
'$_SESSION[last_reminder_id]'";

what is the correct syntax and/or can anyone point me at a
reference that will explain this ?

View Replies !
How To Convert "smart" (curly) Quotes Into Straight Quotes
I've been struggling for a few days with the question of how to convert "smart" (curly) quotes into straight quotes. I tried playing with the htmlentities() function, but all that is doing is changing the smart quotes into nonsense characters. I also searched the web for quite a while and was unsuccessful in finding a solution.

if ($content[$k] == """)
$content = substr($content, 0, $k) . "“" . substr
($content, $k+1, strlen($content)-$k+1);

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 !
Is There A Difference In Doubble Quotes "" And Single Quotes ''
im trying to learn php and i have a question that i can not find an answer to is there a difference in doubble quotes "" and single quotes '' in php and if soo how do i use them correctly.

View Replies !
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?

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 !
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 !
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 !
Quotes And Double Quotes
This is got to be the most annoying aspect of php. Quotes and double quotes. I am running around the house ripping my hair out and throwing tantrums for the past hour or more. I just cannot get past this error. Code:

echo "<td width=&#3970;%' class='list' align='left'><? echo $data['license_key']; ?></td>
";

The problem is here, ><? echo $data['license_key']; ?>

I have tried every possible combination of quotes and double quotes and still keep getting this error.

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved