开发者

change array number of defined string by increment - flat file database + ajax

I'm learning php. Novice. For that purpouse I decided to start with a flat file comment system.

I'm using ajax to post to php that writes data to a flat-file database. Similar to: 12.01.2011¦¦the name¦¦the comment¦¦md5email¦¦0 Where '0' is the start number of comment 'likes'...thumbs-up. Everything is working fine with ajax. Even the comment delete.

At page load jquery counts the comments (starting from 0) and assigns to each's comment-'like' an numbered id. That number is than posted via ajax开发者_开发知识库 to php, resulting the file line number to modify. That system works great for identifying the line to delete. And it deletes the right line!

Now, having the line (or string?) number. How to: Search the file for that line. (foreach...?!...) Finded the line - split it into arrays. (Explode...?) And increment by 1 the defined array value. Limit maximum likes to 99. (1 per user session). Write file, close and so on. - I just can't start count the 'like' clicks. Please help.

Any ideas? Thanks in advance!


$lines = file($filename, FILE_IGNORE_NEW_LINES);
$entry = explode('¦¦', $lines[$linenumber]);
$entry[4]++;
$lines[$lineNumber] = implode('¦¦', $entry);
file_put_contents($filename, implode("\n", $lines));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜