amitjoc/breakify

Handle new line or line break across different platform (windows, unix, mac) and envirnoment like web, cli

Maintainers

Package info

github.com/amitjoc/breakify

pkg:composer/amitjoc/breakify

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 3

v0.1.0 2025-10-30 19:06 UTC

This package is auto-updated.

Last update: 2026-03-05 05:32:43 UTC


README

Breakify is a lightweight PHP utility for managing and transforming line breaks across platforms and formats. Whether you're normalizing text input, preparing content for HTML output, or ensuring consistent formatting in logs or CLI tools, Breakify offers a clean, expressive API to handle it all.

Author

Amit Joshi
Backend Developer | PHP & JavaScript Specialist
GitHub: @amitjoc
LinkedIn: @amitjoc

PHP Version License Build Status Code Style Issues Stars

Table of Contents

Installation

Download the Breakify library

 composer require amitjoshi/breakify

Include composer autoload file

 include_once dirname(__DIR__) . "/vendor/autoload.php"; 

Create a Breakify object

  $web = new Breakify();

Environment

  • WEB: Use when a script runs only in browser-based environments.
  • CLI: Use when a script runs only in command-line environments.
  • BOTH: Use when the environment is dynamic or unknown.

Feature List

  • Web Example and CLI Example
  • beap() (bell sound for CLI)
  • Normalize or convert line breaks across different platforms (Windows \r\n, Unix \n, Mac \r)
  • Handle other escape character too for cli (in progress)

Example for WEB

When we already know that our script only executed on WEB environment

  • print br tag
  $web = new Breakify()
  $web->pbr();        // OUTPUT: Print's `break tag` directly
  $web->phr();        // OUTPUT: <hr />
  $web->phrDashed();  // OUTPUT: ------- 
  $web->phrDotted();  // OUTPUT: .......
  $web->phrRidge();   // OUTPUT: _______
  $web->phrDouble();  // OUTPUT: =======

Example for CLI

When we already know that our script only executed on cli environment

$cliBreak = new Breakify();

$cliBreak->getLineBreak()   //  returns `PHP_EOL`
$cliBreak->pNewLine()       //  echoes single line break
$cliBreak->pNewLine(true)   //  echoes double line break
  • print carriage return also \r
  • print text withing the box with desired character like —, = (in progress)
  • Make a bell sound beap() from php (available only in cli mode)

Important

  1. functions with p prefix directly give output like pbr(),phr(),pLineBreak()

Task List

Default

  • CLI: Default LineBreak is set to PHP_EOL
  • WEB: Default LineBreak is <br />

Functions

  • isCliEnv() function will check is execution environment. return true for cli else false
  • exeEnvType() Type WEB | CLI. it will return the output accordingly

Functions for web

  • print break tag pbr()
  • print horizontal tag phr()
  • print dashed line use function phrDashed()
  • print dotted line use function phrDotted()
  • print ridge line use function phrRidge()
  • print double line use function phrDouble()
  • custom hr line width and height and center also with in build stylesheet

Coding Standard

  • PSR 4 or PSR12