Jump to content

Recommended Posts

I have some code and I'm trying to figure out how to manipulate the array results. The code takes a text file as input. The text file is essentially a set of "records" with each "field" a separate line designated by an initial letter. For example:

 

abob

b12345

[email protected]

ajim

b54321

[email protected]

 

I am using an array to gather the content. The way I have it the array gets the correct lines and it prints out fine but still in the

 

bline

cline

 

format. I would like to be able to have it print out with the line, then a delimiter, then the second line such as

 

bline:cline

bline:cline

 

etc.

 

Any help would be greatly appreciated. Here is the code I'm using.

 

$lines_to_fetch = array('b','c');

 

$inputfile = fopen("filename", "r");

 

if ($inputfile) {

while (!feof($inputfile)) {

$linedesignator = fread($inputfile, 1);

$content = fgets($inputfile);

$contentlower = strtolower($content);

if (in_array($linedesignator,$lines_to_fetch)) {

echo $contentlower;

}

}

fclose($inputfile);

 

 

Link to comment
https://forums.phpfreaks.com/topic/110364-manipulating-array-content/
Share on other sites

Actually it is NOT a "homework" assignment but a real world issue at a major university and not an uncommon input format at all. Thanks for the attitude.

 

Hopefully there are some REAL experts out there that can provide some insight. Thanks in advance.

Actually it is NOT a "homework" assignment but a real world issue at a major university and not an uncommon input format at all. Thanks for the attitude.

 

Hopefully there are some REAL experts out there that can provide some insight. Thanks in advance.

LOL.

 

Seriously, what kind of major university would have real world coding like that?

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.