tshw/php-todo-txt
最新稳定版本:v0.1.0
Composer 安装命令:
composer require tshw/php-todo-txt
包简介
PHP library for the todo.txt unstructured todo list format.
README 文档
README
PHP library for the todo.txt unstructured todo list format.
What is todo.txt?
It's a simple file format for the todo text file that many people probably have on their desktop somewhere.
A todo.txt file following this standard looks like this:
A simple task is just a line
x This task is done, indicated by the lowercase x
(F) Prioritization is important, so this is priority F
2025-01-01 This task has its creation date mentioned
x 2025-01-01 2024-05-01 This task is done and has a completion and creation date
For +myCoolProject I need to write documentation
When I'm @work I need to plan my next vacation
You get the gist. It's simple, but more structured than just writing down stuff.
To lean more, you can head to todotxt.org to learn more.
Features
- Robustly parses the todo.txt
- Provides an easy-to-use model to access and modify tasks
- Task description is available als "clean" version without trailing tags
- Projects, contexts and meta data are available separately as arrays
Installation
Use composer to add as dependency:
$ composer require tshw/php-todo-txt
Usage
Create an object of the main class by reading tasks from a file:
<?php require 'vendor/autoload.php'; $todos = \PhpTodoTxt\TodoTxt::readFromFile(new \SplFileInfo("todo.txt")); // or if don't want to think about the SPL $todos = \PhpTodoTxt\TodoTxt::readFromFile("todo.txt");
List all tasks:
foreach ($todos as $task) { echo $task->getText(); echo $task->isDone() ? 'Done' : 'TODO'; }
Modify tasks:
$todos[4]->done(); $todos[5]->addProject('myFancyProject');
Write tasks to a file:
$todos->writeToFile(\SplFileInfo("todo.txt"));
Add task:
$task = (new Task("Another task", "F")); $todos->addTask($task);
Move task within the list (this displaces tasks further down in the list, changing their keys!):
$todos->moveTask($task, 2);
FAQ
Can I use PHPTodoTxt to store tasks in a database?
Absolutely. For now, the easiest way is to use toStringArray() and fromStringArray() and then you have to implement
storing and reading to/from the database yourself:
$tasks = readTasksFromDatabase(); // must return an array of strings, one task per line $todos = TodoTxt::fromStringArray($tasks); // do whatever with the list $tasks = $todos->toStringArray(); writeTasksToDatabase($tasks);
License
This code is offered open-source under the GPLv3 license.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-06-20