/    Sign up×
Community /Pin to ProfileBookmark

Split File Data

Hi,

How do I store a list of Firstnames & Surnames inside a .txt file, then using PHP,
limit the amount of data displayed per page to only 6 records.

Depending on the number of records stored in the .txt file, a NEXT and PREVIOUS link is enabled/disabled.

Extremely Appreciated!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@TJ111May 23.2008 — Use fgets(), it returns a string from a line in a file. So, for example.

[code=php]
$fh = fopen('file.txt', 'r');
$lines = 0;
$content = '';
while (!feof($fh)) {
$x = fgets($fh);
$content .= ($lines <= 6) ? $x : '' ;
$lines++;
unset($x); //might help memory
}

print $content;
if ($lines > 6) {
print "<a>Next</a>";
}[/code]


Probably not the best method, as it parses the entire file, even after 6 lines or whatever, but hopefully gives you an idea on how to use it.
Copy linkTweet thisAlerts:
@andre4s_yMay 24.2008 — Depent on how you separate one Firstnames & Surnames with the other.

The idea is :
[LIST=1]
  • [*]Read the file with file_get_contents()
  • [*]split it with explode()
  • [*]Process it with array functions

  • [/LIST]

    If you separate one Firstname & Surnames with the other using new line, which mean one firstname & surenames per line, you can use :
    [LIST=1]
  • [*]Read the file with file()
  • [*]Process it with array functions

  • [/LIST]


    But this all still : parses the entire file.

    Why not use database such as : SQLite? ?
    ×

    Success!

    Help @Dysan spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.14,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...