473,811 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_addr esses = count($addresse s);
if ($number_of_add resses == 0)
{
echo "No addresses to process";
}

echo "<table>";

for($i=1; $i<$number_of_a ddresses; $i++)
{
//split each line or row
$line = explode("\t",$a ddresses[$i]);

TIA

More info if required

Oct 30 '05 #1
2 8685
Techie Guy wrote:
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.
Simple.

//read in the name and address lines from the txt file
//each line becomes an element in the array
$addresses= file("download. txt");
This is a rather barbaric way to read in a file. What happens if the
file is larger than the memory PHP is allowed to use? You should
concider reading the file in line by line instead with the following:

$fp = fopen('download .txt', 'r');

while(!feof($fp ))
{
$line = fgets($fp);
/* do stuff */
}

fclose($fp);

//count the number of address lines in the array
$number_of_addr esses = count($addresse s);
if ($number_of_add resses == 0)
{
echo "No addresses to process";
}

echo "<table>";

for($i=1; $i<$number_of_a ddresses; $i++)
{
//split each line or row
Before you split the line using explode, simply do:

$line = explode("\t", str_replace('"' , '', $addresses[$i]));
$line = explode("\t",$a ddresses[$i]);

TIA

More info if required


TIA? IMHO this is bad netiquette - if you can't be bothered to take the
time to write out "Thanks in advance" why should we be bothered to help?

Cheers,

Joe
Oct 30 '05 #2
On Sun, 30 Oct 2005 15:01:07 GMT, Joe Estock
<je*****@NOSPAM nutextonline.co m> wrote:
Techie Guy wrote:
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.
Simple.

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


This is a rather barbaric way to read in a file. What happens if the
file is larger than the memory PHP is allowed to use? You should
concider reading the file in line by line instead with the following:

$fp = fopen('download .txt', 'r');

while(!feof($f p))
{
$line = fgets($fp);
/* do stuff */
}

fclose($fp);


Point taken the file rarely has more than 20 lines but I will use the
code supplied because I think it is an improvement.

//count the number of address lines in the array
$number_of_addr esses = count($addresse s);
if ($number_of_add resses == 0)
{
echo "No addresses to process";
}

echo "<table>";

for($i=1; $i<$number_of_a ddresses; $i++)
{
//split each line or row


Before you split the line using explode, simply do:

$line = explode("\t", str_replace('"' , '', $addresses[$i]));


I had thought of the str_replce function but couldn't think how to use
it... thank you.
$line = explode("\t",$a ddresses[$i]);

TIA

More info if required


TIA? IMHO this is bad netiquette - if you can't be bothered to take the
time to write out "Thanks in advance" why should we be bothered to help?


Assuming that the reason for using TIA is "can't be bothered to take
the time to write it out", then I agree it could be poor netiquette.
However if there is another reason for it's use then it's not poor
netiquette.

Cheers,

Joe


Cheers and thanks again
Oct 30 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
5891
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array with the following elements arr(0) = "MyString" arr(1) = 40 arr(2) = "Hello world"
24
4410
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what we covered was within the last week of the class and all self taught. Our prof gave us an example of a Java method used to remove elements from an array: public void searchProcess() { int outIt=0;
6
6120
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
2
10043
by: Sheldon | last post by:
I'm using DoCmd.TransferText acImportDelim... to import a tab-delimited ..txt file using an Import Specification file and that works fine. The problem is that a few records could have double-quotes in one of the ten fields and that causes an "Unparsable Record" error and the remaining fields for those records are blank. This is part of a process that should not require manual intervention i.e. using an editor to remove the ". Is there a...
4
12784
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or double-quotes or not inside any quotes? If so how? Thanks in advance: Michael Yanowitz
1
2823
by: Al G | last post by:
Hi, I am reading a CSV file with the code below. When I run into a " (quote mark) in the file, I get a "malformed line" exception. Can anyone point me to a way to handle this? Thanks in advance, Al G
2
7344
by: beatTheDevil | last post by:
Hey guys, As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */ comments. I'm using Ruby v.1.8.6 Here's my regex: multiline_comments = /\/\*(.*?)\*\// When I try myStr.gsub(multiline_comments, "")
6
5743
by: Schroeder, AJ | last post by:
Hello group, I am attempting to remove double quotes from the beginning and ending of a string. Admittedly, I am not the best with regular expressions, but I do have two that work with preg_replace(). Here they are: $pattern = ''; <--- removes the beginning double quote $pattern = ''; <--- removes the ending double quote But when I try to make this all one statement with:
7
2848
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds to support cloning: Public Class RefClass Public tcp As TcpClient Public name As String End Class Public Class RefClassList Inherits List(Of RefClass) Implements ICloneable
0
9728
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10648
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10135
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9205
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.