1. Go to this page and download the library: Download t-labs-co/formatter 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/ */
t-labs-co / formatter example snippets
use TLabsCo\Formatter\Formatter;
$formatterRules = [
'title' => 'trim|replace:Local Composer Dependencies,[Local Composer Dependencies]|replace:[Local Composer Dependencies],[Composer Dependencies]|limit:150',
'publish_date' => 'date_format:Y-m-d',
];
$data = [
'title' => ' How to resolve missing Local Composer Dependencies on CentOS 8? ',
'publish_date' => '2024/05/02 13:00'
];
$formatted = Formatter::make($data, $formatterRules)->format()->formatted();
/*
Output:
$formatted = [
'title' => 'How to resolve missing [Composer Dependencies] on CentOS 8?',
'publish_date' => '2024-05-02'
];
*/
use TLabsCo\Formatter\Rules\FormatterRule;
class Max100FormatRule extends FormatterRule
{
public function format($attribute, $value)
{
if (strlen($value) > 100) {
return substr($value, 0, 100);
}
return $value;
}
}
// Using with custom rule
use TLabsCo\Formatter\Formatter;
$formatterRules = [
'title' => 'trim|replace:Local Composer Dependencies,[Local Composer Dependencies]|replace:[Local Composer Dependencies],[Composer Dependencies]|limit:150',
'publish_date' => 'date_format:Y-m-d',
'short_description' => ['trim', new Max100FormatRule()],
];
$data = [
'title' => ' How to resolve missing Local Composer Dependencies on CentOS 8? ',
'publish_date' => '2024/05/02 13:00',
'short_description' => 'Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description '
];
$formatted = Formatter::make($data, $formatterRules)->format()->formatted();
/*
Output:
$formatted = [
'title' => 'How to resolve missing [Composer Dependencies] on CentOS 8?',
'publish_date' => '2024-05-02',
'short_description' => 'Very long description Very long description Very long description Very long description Very long de'
];
*/
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.