Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

String Formatter Laravel Package

respect/string-formatter

Flexible PHP string formatting library with chainable formatters and templated placeholders. Mask, pattern, date, number, and more to transform/format values (e.g., credit cards, phones, amounts) via FormatterBuilder or PlaceholderFormatter modifiers.

View on GitHub
Deep Wiki
Context7

Respect\StringFormatter

Build Status Code Coverage Latest Stable Version Total Downloads License

A powerful and flexible PHP library for formatting and transforming strings.

Installation

composer require respect/string-formatter

Usage

You can use individual formatters directly or chain multiple formatters together using the FormatterBuilder:

echo f::create()
    ->mask('7-12')
    ->pattern('#### #### #### ####')
    ->format('1234123412341234');
// Output: 1234 12** **** 1234

Using Formatters as Modifiers

The PlaceholderFormatter allows you to use any formatter as a modifier within templates:

use Respect\StringFormatter\PlaceholderFormatter;

$formatter = new PlaceholderFormatter([
    'date' => '2024-01-15',
    'amount' => '1234.56',
    'phone' => '1234567890',
]);

echo $formatter->format('Date: {{date|date:Y/m/d}}, Amount: ${{amount|number:2}}, Phone: {{phone|pattern:(###) ###-####}}');
// Output: Date: 2024/01/15, Amount: $1,234.56, Phone: (123) 456-7890

See the PlaceholderFormatter documentation and FormatterModifier documentation for more details.

Formatters

Formatter Description
AreaFormatter Metric area promotion (mm², cm², m², a, ha, km²)
CreditCardFormatter Credit card number formatting with auto-detection
DateFormatter Date and time formatting with flexible parsing
ImperialAreaFormatter Imperial area promotion (in², ft², yd², ac, mi²)
ImperialLengthFormatter Imperial length promotion (in, ft, yd, mi)
ImperialMassFormatter Imperial mass promotion (oz, lb, st, ton)
LowercaseFormatter Convert string to lowercase
MaskFormatter Range-based string masking with Unicode support
MassFormatter Metric mass promotion (mg, g, kg, t)
MetricFormatter Metric length promotion (mm, cm, m, km)
NumberFormatter Number formatting with thousands and decimal separators
PatternFormatter Pattern-based string filtering with placeholders
PlaceholderFormatter Template interpolation with placeholder replacement
SecureCreditCardFormatter Masked credit card formatting for secure display
TimeFormatter Time promotion (mil, c, dec, y, mo, w, d, h, min, s, ms, us, ns)
TrimFormatter Remove whitespace from string edges
UppercaseFormatter Convert string to uppercase

Contributing

Please see our Contributing Guide for information on how to contribute to this project.

License

This project is licensed under the ISC License - see the LICENSE file for details.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle