Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

explode()

 
   Database Help (Home) -> PHP RSS
Next:  Top 10 Things To Look For In A Web Host  
Author Message
Bobby

External


Since: Aug 25, 2008
Posts: 2



(Msg. 1) Posted: Mon Aug 25, 2008 10:48 am
Post subject: explode()
Archived from groups: alt>php (more info?)

I generate a text file created by a Memo Field in a Delphi application. This
gets uploaded to my web server to populate a MySql database table.
The text file uses the '|' (vertical bar) as a delimiter. A typical .txt
file looks like this:

1234|4567|My Name|Panasonic|
Super DeLuxe|Details Bla Bla Bla

I use the explode fuction thus:

$f_array = file("updateclient.txt"); //extract data from file

$ting = explode("|",$f_array[0]);

$job = trim($ting[0]);
$code = trim($ting[1]);
$name = trim($ting[2]);
$make = trim($ting[3]);
$model = trim($ting[4]);
$details = trim($ting[5]);

My problem is this:

The explode function terminates(breaks) after array[3] due to the line feed
(escape) - so that the strings $ting[4] and $ting[5] are empty and the MySql
table cannot be updated.

If I manually modify the file thus:
1234|4567|My Name|Panasonic|Super DeLuxe|Details Bla Bla Bla
.... into one long line all is OK and obviously the table gets updated.

Any ideas as to how to get the array into all the strings using the file as
first described?

Hope I have explained clearly enough?

All help appreciated.

 >> Stay informed about: explode() 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 3780



(Msg. 2) Posted: Mon Aug 25, 2008 10:48 am
Post subject: Re: explode() [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Bobby wrote:
> I generate a text file created by a Memo Field in a Delphi application. This
> gets uploaded to my web server to populate a MySql database table.
> The text file uses the '|' (vertical bar) as a delimiter. A typical .txt
> file looks like this:
>
> 1234|4567|My Name|Panasonic|
> Super DeLuxe|Details Bla Bla Bla
>
> I use the explode fuction thus:
>
> $f_array = file("updateclient.txt"); //extract data from file
>
> $ting = explode("|",$f_array[0]);
>
> $job = trim($ting[0]);
> $code = trim($ting[1]);
> $name = trim($ting[2]);
> $make = trim($ting[3]);
> $model = trim($ting[4]);
> $details = trim($ting[5]);
>
> My problem is this:
>
> The explode function terminates(breaks) after array[3] due to the line feed
> (escape) - so that the strings $ting[4] and $ting[5] are empty and the MySql
> table cannot be updated.
>
> If I manually modify the file thus:
> 1234|4567|My Name|Panasonic|Super DeLuxe|Details Bla Bla Bla
> ... into one long line all is OK and obviously the table gets updated.
>
> Any ideas as to how to get the array into all the strings using the file as
> first described?
>
> Hope I have explained clearly enough?
>
> All help appreciated.
>
>
>
>
>

Either fix the input file, or use another function to read it - such as
fread(), and strip out the newline characters.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex DeleteThis @attglobal.net
==================

 >> Stay informed about: explode() 
Back to top
Login to vote
Bobby

External


Since: Aug 25, 2008
Posts: 2



(Msg. 3) Posted: Tue Aug 26, 2008 8:55 pm
Post subject: Re: explode() [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Jerry Stuckle" wrote in message

wrote:
> Either fix the input file, or use another function to read it - such as
> fread(), and strip out the newline characters.

Thanks.
 >> Stay informed about: explode() 
Back to top
Login to vote
bizshop

External


Since: May 07, 2008
Posts: 4



(Msg. 4) Posted: Wed Aug 27, 2008 12:24 am
Post subject: Re: explode() [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Aug 25, 3:48 am, "Bobby" wrote:
> I generate a text file created by a Memo Field in a Delphi application. This
> gets uploaded to my web server to populate a MySql database table.
> The text file uses the '|' (vertical bar) as a delimiter. A typical .txt
> file looks like this:
>
> 1234|4567|My Name|Panasonic|
> Super DeLuxe|Details Bla Bla Bla
>
> I use the explode fuction thus:
>
> $f_array = file("updateclient.txt"); //extract data from file
>
>  $ting = explode("|",$f_array[0]);
>
>  $job = trim($ting[0]);
>  $code = trim($ting[1]);
>  $name = trim($ting[2]);
>  $make = trim($ting[3]);
>  $model = trim($ting[4]);
>  $details = trim($ting[5]);
>
> My problem is this:
>
> The explode function terminates(breaks) after array[3] due to the line feed
> (escape) - so that the strings $ting[4] and $ting[5] are empty and the MySql
> table cannot be updated.
>
> If I manually modify the file thus:
> 1234|4567|My Name|Panasonic|Super DeLuxe|Details Bla Bla Bla
> ... into one long line all is OK and obviously the table gets updated.
>
> Any ideas as to how to get the array into all the strings using the file as
> first described?
>
> Hope I have explained clearly enough?
>
> All help appreciated.

You need to break it down by line, as in:
foreach ($f_array as $line_num => $line) {
Then do the exploding on each line, followed by mysql insertion
then it moves on to the next
}
 >> Stay informed about: explode() 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
explode - Hi All, I'm trying to use explode to separate the result of a textual file, but it explode me only the first row. the foo.txt is pippo pluto pluto pippo pippo pippo .... I use this script found in http://it2.php.net/manual/en/function.explode.php ..

Query on explode() - Hi All, Have a look at the following code $test = explode('-','one-two-three-four-five'); print_r($test); Output: Array ( [0] => one [1] => two [2] => three [3] => four [4] => five ) But Wh...

help needed for mailing HTMl content - hai...can someone plzz help me in writing a class to send Mails with HTML content. Try to suggest some working Class library if there is any on the web so that i may not re-invent the wheel. thanx...

Output XML file! - I have a XML variable (string). I want to output it to a XML file. I'm using <?php header("Content-type: application/gps"); header("Content-Disposition: attachment; filename=paring.xml"); print $xml; ?> But I get an error ...

I need a fat server..... - I am looking for an inexpensive or free hosting server where I can store extra user uploaded files (beyond my current host). Don't care about the bells and whistles, just need tons of bulk space that can be hyperlinked and FTP'd to mostly. Any pointers...
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]