Jump to content

preg_replace...


j007ha

Recommended Posts

i have a text file which is i going to store all of the data in the text file into a database.

 

For example:

|AR_CUSTNO |AR_CUSTNME |AR_ADD1 |AR_ADD2 |AR_ADD3 |AR_ADD4 |AR_TELNO

 

in the text file all of the column is seperate by a " | " sign...so how i using preg_replace to get rid of the

" | " sign ? so i can insert all the data into the database table.

 

thx for any reply^^

Link to comment
Share on other sites

hehe I used to do this before I used mysql..

try..

 

<?php
//--MYSQL_CONNECT ETC GOES HERE--//

  $ft = fread(fopen("FILENAME.txt", "r"), filesize("FILENAME.txt"));
  $fr = explode("
", $ft);
  $i = 0;
  foreach($fr as $value) {
     $fa = explode("|", $value);
     @mysql_query("insert into TABLE(CustNum, CustName, AR_ADD1, AR_ADD2, AR_ADD3, AR_ADD5, AR_TELNO) values('$fa[0]', '$fa[1]', '$fa[2]', '$fa[3]', '$fa[4]', '$fa[5]', '$fa[6]')");
  }
?>

 

that's how I did it anyway.. If I remember right..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.