PHP code example of clytras / lyx

1. Go to this page and download the library: Download clytras/lyx 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/ */

    

clytras / lyx example snippets


// Simple Str::format example

Lyx\Strings\Str::format("This is a simple {0} for {1} ('{0}', '{1}')", [
  'format',
  'testing'
]));

// This is a simple format for testing ('format', 'testing')

// Using assosiative arrays and constants

use Lyx\Strings\Str;

define("C_TEST", 'Const test!');

lyx_print(Str::format(
  "This is an assoc keys {example} for {purpose} [{C_TEST}] ('{example}', '{purpose}')",
  [
    'example' => 'Case',
    'purpose' => 'Testing'
  ]
));

// This is an assoc keys Case for Testing [Const test!] ('Case', 'Testing')

// Using assosiative nested arrays

use Lyx\Strings\Str;

lyx_print(Str::format(
  "This is an assoc keys {example.arg1} for {purpose.a1} ('{example.arg2}', '{purpose.a2}')",
  [
    'example' => [
      'arg1' => 'Example - Arg 1',
      'arg2' => 'Ex - Arg 2'
    ],
    'purpose' => [
      'a1' => 'Testing 1',
      'a2' => 'Test 2'
    ]
  ]
));

// This is an assoc keys Example - Arg 1 for Testing 1 ('Ex - Arg 2', 'Test 2')

// Numbers zero padding, decimal point precision and converters

use Lyx\Strings\Str;

$nums = [123, 1.23, 19000321, 0xEE, 0xA5F];
$numCases = [
  'single_numbers' => [
    'format' => "{0} / {1} / {2}"
  ],
  'zero_padding/dec_point = ./thousand_sep = ,' => [
    'format' => "{0,.3} / {1,3.4} / {2,/.2}",
    'options' => [
      'dec_point' => ',',
      'thousands_sep' => '.'
    ]
  ],
  'zero_padding/dec_point = ,/thousand_sep = .' => [
    'format' => "{0,.3} / {1,3.4} / {2,/.2}"
  ],
  'base/hex' => [
    'format' => "{3:x} / 0x{3:X,6} / {4:x} / 0x{4:X,4}"
  ],
  'base/oct' => [
    'format' => "{3:o} / 0{3:o,5} / {4:o} / 0{4:o,4}"
  ],
  'base/bin' => [
    'format' => "{3:b} / 0b{3:b,8} / {4:b} / 0b{4:b,16}"
  ]
];

foreach($numCases as $name => $case) {
  echo "{$name}: ";
  lyx_println(Str::format($case['format'], $nums, $case['options'] ?? []));
}

// Using simple color formating or print removing the formating tags

use Lyx\System\Terminal;

$str = 'Test: <f:red,b:blue>This<f> <b:red>and<b> <f:green,a:underline>more<> <f:light-green>colors<f> <a:reverse:underline>test<a>';

// Print the text with terminal color formating
Terminal::println($str);

// Print the raw text without color formating tags
Terminal::printlnRaw($str);

// Using templates to set color formating with regular expressions

use Lyx\System\Terminal;

$html = <<<HTML
<html lang="en">
 <head>
  <title>
    A Simple HTML Document
  </title>
 </head>
 <body bgcolor="#E6E6FA">
  <p align="center">This is a very simple HTML document</p>
  <p>It only has two paragraphs</p>
 </body>
</html>
HTML;

Terminal::printTmpl($html, [
  // Use green to color all the tags
  '/<(.|\\n)*