PHPackages                             paper-cello/paper-cello - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. paper-cello/paper-cello

ActiveLibrary

paper-cello/paper-cello
=======================

miscellaneous PHP functions

0.6.0(10y ago)0661MITPHPPHP &gt;=5.3.0

Since Aug 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/al-codepone/paper-cello)[ Packagist](https://packagist.org/packages/paper-cello/paper-cello)[ Docs](https://github.com/al-codepone/paper-cello)[ RSS](/packages/paper-cello-paper-cello/feed)WikiDiscussions master Synced today

READMEChangelog (2)DependenciesVersions (3)Used By (1)

Paper Cello
===========

[](#paper-cello)

Paper Cello is a library of miscellaneous PHP functions. There are functions for datetimes, bcrypt hashing, clamping, pagination, routing and SHA1 token generation.

Documentation
-------------

[](#documentation)

All functions have a DocBlock. So you can read the source code or generate documentation with [phpDocumentor](http://phpdoc.org/).

Requirements
------------

[](#requirements)

**PHP 5.3** or greater

Source Code
-----------

[](#source-code)

The [project](https://github.com/al-codepone/paper-cello) is on GitHub. All the source code is in [this file](https://github.com/al-codepone/paper-cello/blob/master/src/paper-cello.php).

Tests
-----

[](#tests)

All tests are in the [test directory](https://github.com/al-codepone/paper-cello/tree/master/test). There is a test for each function; the name of the test script is the function name.

Installation
------------

[](#installation)

Install using composer:

```
{
    "require": {
        "paper-cello/paper-cello": "0.6.0",
    }
}
```

or you can install manually:

```
require 'paper-cello.php';
```

datetime\_now() and datetime\_to()
----------------------------------

[](#datetime_now-and-datetime_to)

Use `datetime_now()` and `datetime_to()` to handle datetimes. These functions handle time zones and daylight saving time correctly without having to use any other time settings.

Get the current UTC datetime with `datetime_now()`:

```
$utc_now = pc\datetime_now(); //2014-07-24 04:33:12
```

Use `datetime_to()` to convert a UTC datetime to a time zone and format:

```
echo pc\datetime_to($utc_now, 'America/Los_Angeles', 'M j, Y g:ia');

//Jul 23, 2014 9:33pm
```

bcrypt\_hash()
--------------

[](#bcrypt_hash)

Use `bcrypt_hash()` to hash passwords. Use either a cost value from 4-31:

```
$hash = pc\bcrypt_hash('password', 12);

//$2a$12$DMWzyZ.iU444JC/.270Bqe84eIwqHOD7ct4jkHY/0gaNv98fHNGx.
```

Or use a previously obtained hash:

```
echo pc\bcrypt_hash('password', $hash);

//$2a$12$DMWzyZ.iU444JC/.270Bqe84eIwqHOD7ct4jkHY/0gaNv98fHNGx.
```

clamp()
-------

[](#clamp)

Clamp a value to a range:

```
echo implode(', ', array(
    pc\clamp(5, 1, 10),
    pc\clamp(0, 1, 10),
    pc\clamp(11, 1, 10),
    pc\clamp(11, 1, 10.4),
    pc\clamp('d', 'c', 'f'),
    pc\clamp('a', 'c', 'f'),
    pc\clamp('i', 'c', 'f')));

//5, 1, 10, 10.4, d, c, f
```

paginate()
----------

[](#paginate)

Compute total number of pages and current page number given number of items, items per page and raw current page number:

```
$num_items = 24;
$items_per_page = 5;
$raw_current_page_num = 2;

var_dump(pc\paginate(
    $num_items,
    $items_per_page,
    $raw_current_page_num));

/*
array
  0 => int 5
  1 => int 2
*/
```

route()
-------

[](#route)

Use `route()` to include one of many PHP scripts based on a value. These examples use `echo`; use `require` in your application.

Route on the default `$_GET['r']`:

```
echo pc\route(array(
    null => 'home.php',
    'contact' => 'contact.php'));

//home.php
```

Use a base directory:

```
echo 'my/route/' . pc\route(array(
    null => 'home.php',
    'contact' => 'contact.php'));

//my/route/home.php
```

Route on a POST value:

```
echo pc\route(
    array(
        null => 'one.php',
        'two' => 'two.php'),
    $_POST['r']);

//one.php
```

Route on a value for testing:

```
echo pc\route(
    array(
        null => 'home.php',
        'chess' => 'chess.php',
        'golf' => 'golf.php'),
    'golf');

//golf.php
```

There is a shortcut so you don't have to specify keys in the array. For example the below is equivalent to the above:

```
echo pc\route(
    array(
        null => 'home.php',
        'chess.php',
        'golf.php'),
    'golf');

//golf.php
```

sha1\_token()
-------------

[](#sha1_token)

Get a random token:

```
echo pc\sha1_token(); //003046aec403e654eaadad31658bcad04ad7f95c
```

LICENSE
-------

[](#license)

MIT

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~574 days

Total

2

Last Release

3723d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dde0ea39d89e43216fff0c3b80d61ffd6293e9632d5b6f2f20ca48847cba7894?d=identicon)[hadramoo](/maintainers/hadramoo)

---

Top Contributors

[![ferg1e](https://avatars.githubusercontent.com/u/2236096?v=4)](https://github.com/ferg1e "ferg1e (26 commits)")

---

Tags

routertokendatetimehashpaginatebcryptsha1clamp

### Embed Badge

![Health badge](/badges/paper-cello-paper-cello/health.svg)

```
[![Health](https://phpackages.com/badges/paper-cello-paper-cello/health.svg)](https://phpackages.com/packages/paper-cello-paper-cello)
```

###  Alternatives

[symfony/routing

Maps an HTTP request to a set of configuration variables

7.6k789.4M1.8k](/packages/symfony-routing)[slim/slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs

12.2k49.9M1.3k](/packages/slim-slim)[nikic/fast-route

Fast request router for PHP

5.3k92.4M665](/packages/nikic-fast-route)[hashids/hashids

Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers

5.5k48.6M275](/packages/hashids-hashids)[ramsey/collection

A PHP library for representing and manipulating collections.

1.2k486.0M69](/packages/ramsey-collection)[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
