PHPackages                             ccuffs/poll-from-text - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ccuffs/poll-from-text

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ccuffs/poll-from-text
=====================

Convenient package to create polls (questionnaires) from pure text minimally organized in lines.

2.0.0(4y ago)24671MITPHPPHP &gt;=7.3

Since Jun 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ccuffs/poll-from-text)[ Packagist](https://packagist.org/packages/ccuffs/poll-from-text)[ RSS](/packages/ccuffs-poll-from-text/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

 [![](.github/logo.png "Project logo")](.github/logo.png)
 [![](https://camo.githubusercontent.com/ed4b076d510cfd99e26040f288521c15793782e370e031e4b7fb09fe985b29f8/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032323f7374796c653d666f722d7468652d6261646765 "Project status")](https://camo.githubusercontent.com/ed4b076d510cfd99e26040f288521c15793782e370e031e4b7fb09fe985b29f8/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032323f7374796c653d666f722d7468652d6261646765) [![](https://camo.githubusercontent.com/3f1542652b4b04299ca9db31768000f82d57febc28c35884514911febc31cc69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6363756666732f706f6c6c2d66726f6d2d746578742f43493f6c6162656c3d4275696c64266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465267374796c653d666f722d7468652d6261646765 "Build status")](https://camo.githubusercontent.com/3f1542652b4b04299ca9db31768000f82d57febc28c35884514911febc31cc69/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6363756666732f706f6c6c2d66726f6d2d746578742f43493f6c6162656c3d4275696c64266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465267374796c653d666f722d7468652d6261646765)

Introduction
============

[](#introduction)

`poll-from-text` is a PHP package to parse semi-structured text into structured-data that can be used to build questionnaires (forms). The main goal is to allow end users to build dynamic forms, e.g. Google Forms, using plain text like they would if the forms were to be printed on paper.

> **NOTICE:** this package assumes a certain format in the "pure" text, so it might not be as generic as possible. The world has bigger problems.

✨Features
---------

[](#features)

- Simple input questions (useful to create `` elements);
- Question with options (useful to create `` elements);
- Options with no value (only text), e.g. `- Text`, or `* Text` (like in `Text`);
- Options with a value, e.g `a) Text` (value is `"a"`, like in `Text`);
- Data attributes (as JSON objects) for both questions and options, e.g. `{"type":"file"} What?` (useful to create custom form elements such as ``).

🚀 Getting started
-----------------

[](#-getting-started)

### 1. Add this package to your project

[](#1-add-this-package-to-your-project)

At the root of your project, run:

```
composer require ccuffs/poll-from-text

```

### 2. Basic usage

[](#2-basic-usage)

Instantiate the class `CCUFFS\Text\PollFromText` then call `parse()`:

> *Tip:* use `CCUFFS\Text\PollFromText::make()` if you don't want to instantiate an object.

```
$poller = new CCUFFS\Text\PollFromText();
$questions = $poller->parse('Favorite color?')

var_dump($questions);
```

The output should be something like:

```
array(1) {
  [0]=>
  array(2) {
    ["text"]=>
    string(15) "Favorite color?"
    ["type"]=>
    string(5) "input"
  }
}
```

A new line (without the option marks) indicates a new question:

```
$poller = new CCUFFS\Text\PollFromText();
$questions = $poller->parse('
    Favorite color?
    Favorite food?
')

var_dump($questions);
```

The output should be something like:

```
array(2) {
  [0]=>
  array(2) {
    ["text"]=>
    string(15) "Favorite color?"
    ["type"]=>
    string(5) "input"
  }
  [1]=>
  array(2) {
    ["text"]=>
    string(15) "Favorite food?"
    ["type"]=>
    string(5) "input"
  }
}
```

You can create questions with options by prefixing lines with `-` or `*`:

```
$poller = new CCUFFS\Text\PollFromText();
$questions = $poller->parse('
   Choose favorite color
   - Green
');

var_dump($questions);
```

The output should be something like:

```
array(1) {
  [0]=>
  array(3) {
    ["text"]=>
    string(21) "Choose favorite color"
    ["type"]=>
    string(6) "select"
    ["options"]=>
    array(1) {
      ["text"]=>
      string(5) "Green",
      ["marker"]=>
      string(1) "-"
    }
  }
}
```

### 3. Advanced usage

[](#3-advanced-usage)

You can create questions with options and their values by using `)`, for instance:

```
$poller = new CCUFFS\Text\PollFromText();
$questions = $poller->parse('
   Choose favorite color
   a) Green
');

var_dump($questions);
```

The output should be something like:

```
array(1) {
  [0]=>
  array(3) {
    ["text"]=>
    string(21) "Choose favorite color"
    ["type"]=>
    string(6) "select"
    ["options"]=>
    array(1) {
     ["a"]=>
      array(3) {
        ["text"]=>
        string(5) "Green"
        ["marker"]=>
        string(1) "a"
        ["separator"]=>
        string(1) ")"
    }
  }
}
```

Both questions and options accept a json string as a data field, e.g.

```
$poller = new CCUFFS\Text\PollFromText();
$questions = $poller->parse('{"attr":"value", "attr2":"value"} Type favorite color');

var_dump($questions);
```

The output should be something like:

```
array(1) {
  [0]=>
  array(3) {
    ["text"]=>
    string(21) "Type favorite color"
    ["type"]=>
    string(5) "input"
    ["data"]=>
    array(2) {
      ["attr"]=>
      string(5) "value"
      ["attr2"]=>
      string(5) "value"
    }
  }
}
```

Data attribute for an options:

```
$poller = new CCUFFS\Text\PollFromText();
$questions = $poller->parse('
   Choose favorite color
   {"attr":"hi"} a) Green
');

var_dump($questions);
```

The output should be something like:

```
array(1) {
  [0]=>
  array(3) {
    ["text"]=>
    string(21) "Choose favorite color"
    ["type"]=>
    string(6) "select"
    ["options"]=>
    array(1) {
      ["a"]=> array(2) {
          ["text"]=>
          string(5) "Green"
          ["marker"]=>
          string(1) "a"
          ["separator"]=>
          string(1) ")"
          ["data"]=>
          array(1) {
              ["attr"]=>
              string(2) "hi"
          }
      }
    }
  }
}
```

### 3.1 Specific configuration

[](#31-specific-configuration)

Both `parse()` and `make()` accept a `$config` which is an array of configuration to consider when generating the questionnaire. Below is a complete list of all available configuration options:

```
$config = [
    'multiline_question' => false,                   // if `true`, questions are allowed to have `\n` in their text.
    'attr_validation' => PollFromText::ATTR_AS_TEXT, // allow any text a attribute (no validation)
];
```

### 4. Testing (related to the package development)

[](#4-testing-related-to-the-package-development)

If you plan on changing how the package works, be sure to clone it first:

```
git clone https://github.com/ccuffs/poll-from-text && cd poll-from-text

```

Install dependencies

```
composer install

```

Make your changes. After, run the tests it to ensure nothing breaked:

```
./vendor/bin/pest

```

There should be plenty of green marks all over 😁

🤝 Contribute
------------

[](#-contribute)

Your help is most welcome regardless of form! Check out the [CONTRIBUTING.md](CONTRIBUTING.md) file for all ways you can contribute to the project. For example, [suggest a new feature](https://github.com/ccuffs/poll-from-text/issues/new?assignees=&labels=&poll-from-text=feature_request.md&title=), [report a problem/bug](https://github.com/ccuffs/poll-from-text/issues/new?assignees=&labels=bug&poll-from-text=bug_report.md&title=), [submit a pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests), or simply use the project and comment your experience. You are encourage to participate as much as possible, but stay tuned to the [code of conduct](./CODE_OF_CONDUCT.md) before making any interaction with other community members.

See the [ROADMAP.md](ROADMAP.md) file for an idea of how the project should evolve.

🎫 License
---------

[](#-license)

This project is licensed under the [MIT](https://choosealicense.com/licenses/mit/) open-source license and is available for free.

🧬 Changelog
-----------

[](#-changelog)

See all changes to this project in the [CHANGELOG.md](CHANGELOG.md) file.

🧪 Similar projects
------------------

[](#-similar-projects)

Below is a list of interesting links and similar projects:

- [Other project](https://github.com/project)
- [Project inspiration](https://github.com/project)
- [Similar tool](https://github.com/project)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~51 days

Total

3

Last Release

1733d ago

Major Versions

v1.0.1 → 2.0.02021-10-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f050ee8eb11afab6b5b800f25b535baa7452b6a5bb9178dca3f0f0a0d8c1467?d=identicon)[ComputacaoUFFS](/maintainers/ComputacaoUFFS)

---

Top Contributors

[![Dovyski](https://avatars.githubusercontent.com/u/512405?v=4)](https://github.com/Dovyski "Dovyski (22 commits)")

---

Tags

formnlppollsurveyquestionnaire

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/ccuffs-poll-from-text/health.svg)

```
[![Health](https://phpackages.com/badges/ccuffs-poll-from-text/health.svg)](https://phpackages.com/packages/ccuffs-poll-from-text)
```

###  Alternatives

[codefog/contao-polls

polls extension for Contao Open Source CMS

152.7k](/packages/codefog-contao-polls)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
