Jump to content

manipulating array content


klsfriend

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.

LOL.

 

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

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.