2017 © Pedro PelĂĄez
 

library format

Simple function to format strings

image

jderusse/format

Simple function to format strings

  • Friday, December 16, 2016
  • by jderusse
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

 Format

Format provide the ability to do variable substitutions., (*1)

 Installation

composer require jderusse/format

Usage

format('Hello {who}', ['who' => 'World']);

Usecase

throw new \Exception(format('Fail to load resource "{resource}".', ['resource' => $fileName]);
$this->addFlash(format('Project "{name}" succesfully created.', ['name' => $project->getName()]);

Why?

Because I'm not happy with language alternatives., (*2)

- echo 'Should I use "'."'".'" or "'.'"'.'"';
+ echo format('Should I use "{single}" or "{double}"', ['single'=> "'", 'double' => '"']);
- sprintf('%s likes when %s repeat the same things', $user, $user');
+ format('{user} like when {user} repeat the same things', ['user'=> $user]);
- sprintf('%s%s%s', $scheme, $host, $path');
+ format('{scheme}{host}{path}', ['scheme' => $scheme, 'host' => $host, 'path' => $path]);
- echo "Hello {$this->getUser()->getusername()}. Welcome in {$this->getProject()->getName()}":
+ echo format('Hello {user}. Welcome in {project}', ['user' => $this->getUser()->getusername(), 'project' => $this->getProject()->getName()]):

The Versions

16/12 2016

dev-master

9999999-dev

Simple function to format strings

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

string format sprintf

16/12 2016

1.0.0

1.0.0.0

Simple function to format strings

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

string format sprintf