PHP code example of ccuffs / poll-from-text

1. Go to this page and download the library: Download ccuffs/poll-from-text 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/ */

    

ccuffs / poll-from-text example snippets


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

var_dump($questions);

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

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

var_dump($questions);

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"
  }  
}

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

var_dump($questions);

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) "-"
    }
  }
}

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

var_dump($questions);

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) ")"
    }
  }
}

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

var_dump($questions);

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"
    }
  }
}

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

var_dump($questions);

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"
          }
      }
    }
  }
}

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