You are here: Re: Removing quotes from an array, string or txt file see code « PHP Programming Language « IT news, forums, messages
Re: Removing quotes from an array, string or txt file see code

Posted by Joe Estock on 10/30/05 17:01

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_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

Before you split the line using explode, simply do:

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

> $line = explode("\t",$addresses[$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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация