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
https://forums.phpfreaks.com/topic/121510-preg_replace/
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
https://forums.phpfreaks.com/topic/121510-preg_replace/#findComment-626637
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.