Jump to content
xisto Community
Sign in to follow this  
oncombeureum

Fileopen split the comma

Recommended Posts

i implement this

<?$fp = fopen('data.txt', 'r');

if ($fp) {
  while (!feof($fp)) {
      $texts = fread($fp, 4096);
  echo 'this is -> ' . $texts . '\n <br?';
  }
  fclose($fp);
}

?>


for the data file:

data.txtsatu@mon.com,
combo@bakso.com,
special@monyong.com,
kuya.batok@forever.and.ever.com,
special.pake.telor.2@tolong.jangan.lama.com


the result :

this is -> satu@mon.com combo@bakso.com special@monyong.com kuya.batok@forever.and.ever.com special.pake.telor.2@tolong.jangan.lama.com \n

what i want is
can it read line by line ?
no matter how long the line is

danke

Oncom Beureum

Share this post


Link to post
Share on other sites

Using the spilt() function on $text will insert the contents of data.txt into an array if you use the linebreak as the delimiter for the split() function.

This would give you an array like so: (Simplified)

$arrayname[0] = data.txt
$arrayname[1] = satu@mon.com,
$arrayname[2] = combo@bakso.com,
$arrayname[3] = special@monyong.com,
$arrayname[4] = kuya.batok@forever.and.ever.com,
$arrayname[5] = special.pake.telor.2@tolong.jangan.lama.com

Of course this would only be possible if you can predict where your delimiter is located.

You can skip the first array entry several ways depending on whether or not you want that data to be used.

Then to output the data, you'll ned to cycle through the array and output each item idividually.

This isn't a very detailed explaination but I hope it will get you pointed in the right direction.

Try the PHP Site for more information.http://php.net/

Hope this helps,

vujsa

Share this post


Link to post
Share on other sites

Actually, The method split(); is what you need here, but as for the question you asked -

How to read a line

- just use fgets() function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.