PHP code example of tshw / php-todo-txt

1. Go to this page and download the library: Download tshw/php-todo-txt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tshw / php-todo-txt example snippets



os = \PhpTodoTxt\TodoTxt::readFromFile(new \SplFileInfo("todo.txt"));
// or if don't want to think about the SPL
$todos = \PhpTodoTxt\TodoTxt::readFromFile("todo.txt");

foreach ($todos as $task) {
   echo $task->getText();
   echo $task->isDone() ? 'Done' : 'TODO';
}

$todos[4]->done();
$todos[5]->addProject('myFancyProject'); 

$todos->writeToFile(\SplFileInfo("todo.txt"));

$task = (new Task("Another task", "F"));
$todos->addTask($task);

$todos->moveTask($task, 2);

$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);