Current location: Hot Scripts Forums » General Community » Script Requests » Problem with Read from file by PHP


Problem with Read from file by PHP

Reply
  #1 (permalink)  
Old 09-12-03, 06:12 PM
Pothik Pothik is offline
New Member
 
Join Date: Sep 2003
Location: Dhaka
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Problem with Read from file by PHP

I want to read a text file by php code with compare like

file name is 'price.txt'

Data of the file are:
-----------------------------------------------------
Copmany Name Price

Exim Bank 100.00
Standard Bank 120.00
-------------------------------------------------

i want read it and save to database field which are created for that.is it possible?
__________________
Work is Life
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-13-03, 07:46 AM
clay@lazarusid.com clay@lazarusid.com is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Flint, Michigan
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Not only possible but pretty easy. Just read in the line, break it into it's component parts, and insert a record into the database.

Your trick, of course, will be breakup up the component parts, because you have a variable length, undelimited text field followed by a price. It might have been better to reverse the order of the fields, or create some variety of delimiter like a dollar sign. That can be worked out though, just start hunting for the change between whitespace and digits.
__________________
<a href="http://www.lazarusid.com/">www.lazarusid.com</a>

Custom script development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-13-03, 07:59 AM
Pothik Pothik is offline
New Member
 
Join Date: Sep 2003
Location: Dhaka
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy

Thnkx for help but if u give some code for this it would be more helpfull to me coz i am new in php.
__________________
Work is Life
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-13-03, 09:33 AM
ermau's Avatar
ermau ermau is offline
Wannabe Coder
 
Join Date: Aug 2003
Location: Florida, USA
Posts: 240
Thanks: 0
Thanked 0 Times in 0 Posts
For this to work, just add a + in front of each line that contains data, like such:
-----------------------------------------------------
Copmany Name Price

+Exim Bank 100.00
+Standard Bank 120.00
-------------------------------------------------

PHP Code:

<?php


$prices 
file('price.txt');
for (
$i=0$i<count($prices); $i++)
{
      if (
stristr($prices[$i],'+'))
      {
            
$data explode(' ',$prices[$i]);
            
mysql_query("INSERT INTO table (name,price) VALUES ('$data[0]','$data[1]')");
      }
}

?>
Of course I don't know how your mysql table structure is but you can modify that query to your needs.
__________________
PHP / mySQL Developer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-13-03, 11:25 AM
Pothik Pothik is offline
New Member
 
Join Date: Sep 2003
Location: Dhaka
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

Special Thnkx for help .hope it will work properly
__________________
Work is Life
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-15-03, 09:42 AM
clay@lazarusid.com clay@lazarusid.com is offline
Newbie Coder
 
Join Date: Aug 2003
Location: Flint, Michigan
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Pothik,

It sounds like you might be better served by the PHP forum here or over at devshed.com. This isn't really a "help me learn PHP" forum. People in those other forums will be able to help you get up and running though.
__________________
<a href="http://www.lazarusid.com/">www.lazarusid.com</a>

Custom script development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 05:03 AM
file download problem ukyankee Perl 6 10-04-03 11:39 PM
New Web Host, New Problem! justchat PHP 2 09-29-03 03:39 PM
PHP - Dir listing and write to file NickyWhicko PHP 4 08-24-03 03:42 AM
One PHP file to edit another.... drgn91 PHP 10 07-22-03 12:29 PM


All times are GMT -5. The time now is 07:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.