/    Sign up×
Community /Pin to ProfileBookmark

get info frrom a fileand put into an array

i want to get the stuff from my file news.php put them each news entry into an array so i can use the list function. Can i do this.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@SamFeb 28.2004 — yes, i would suggest delimiting your file (adding characters such as pipes (|) to seperate each entry, then using the explode function
Copy linkTweet thisAlerts:
@ConorauthorFeb 28.2004 — awesome . Do you know if i have like <br> in a text file and i include that in an html file will it write in its correct html entitiy?
Copy linkTweet thisAlerts:
@SamFeb 28.2004 — yes, unless you use htmlspecialchars to autoescape it
Copy linkTweet thisAlerts:
@ConorauthorFeb 29.2004 — ok i have this [code=php]<?
$file=file_get_contents('write.txt');
$file_exp=explode("|", $file);
?>[/code]
and it gets the stuff and puts it into an array perfectly but is there anyway to use list() so that everytime something is added to the array(when a new | is added) it is added to the top of the list
Copy linkTweet thisAlerts:
@SamFeb 29.2004 — are these entries gonna contain a date or a #?
Copy linkTweet thisAlerts:
@ConorauthorFeb 29.2004 — yes they will. I have the variables written for them just havent added them im just trying to figure out the list thing.
Copy linkTweet thisAlerts:
@SamFeb 29.2004 — the way i see it, if you're inputing them all into a text file, why not just have them write to the beginning of the file rather than the end, that way you don't have to process as much to pull the strings and sort and such...
Copy linkTweet thisAlerts:
@ConorauthorFeb 29.2004 — you can have it right to the beginning of a file? i had no idea how?
Copy linkTweet thisAlerts:
@SamMar 01.2004 — yes. example, lets say file is in string $string and what you want to add is in $nstring:

fwrite($handle,$nstring . "|" . $string);
×

Success!

Help @Conor 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...