Download the PHP package hashbang/pherl without Composer

On this page you can find all versions of the php package hashbang/pherl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pherl

Pherl - Perl like functionality for PHP

This module is intended to provide simple Perl like functionality for PHP users.

It contains a number of convenience functions cheerfully ripped from the Perl programming languages which make coding a lot easier for the terminally impatient.

Installation

Installing into CodeIgniter / CakePHP etc.

Download this GIT repository and copy into your application directory.

Alternatively, install with Composer.

Since Composer doesn't seem to like just loading files full of helper functions you will need to place:

include('vendor/hashbang/pherl/lib/pherl.php');

Early in your load order to use the provided Pherl functions.

qw - Quick array initalizer

Quickly initalize arrays by providing a single string. The array elements are determined by any whitespace.

// Create an array with three elements (foo, bar and baz)
$array = qw('foo bar baz');

$array = qw('foo    bar    baz');

$array = qw('
    foo
    bar
    baz
');

keyval - Create a key/val relationship from an array-of-arrays

Quickly reorder arrays by picking the key and value arrangement from an array of arrays

$in = array(
    array(
        'name' => 'Earl',
        'age' => 35,
    ),
    array(
        'name' => 'John',
        'age' => 24,
    ),
);

$a = keyval('name', 'age', $in); // $a is now array('Earl' => 35, 'John' => 24)

Specifying 'OFFSET' as the key uses the offset of the index within the array-of-arrays.

values - Extract a key from a hash and return as indexed array

Quickly reorder arrays by picking the key and value arrangement from an array of arrays

$in = array(
    array(
        'name' => 'Earl',
        'age' => 35,
    ),
    array(
        'name' => 'John',
        'age' => 24,
    ),
);

$a = values('name', $in); // $a is now array('Earl', 'John')

values is actually just a shortcut function for keyval(null, $value, $array).

pick - Pick random elements from an array

Choose a single random element from an array.

$item = pick(qw('foo bar baz')); // Chooses either foo, bar or baz

encase - Add a prefix / suffix to an array of strings

The encase() function allows you to quickly enclose each string in an array with a given prefix and suffix.

$tags = encase(qw('a img hr', '<', '>')); // Returns: <a>, <img>, <hr>

The meta string 'OFFSET' will be replaced with the key of the array being iterated over.

evalstr - Expand PHP style strings

Return the computed result of a string using local variables.

echo evalstr('Hello $name', array('name' => 'Matt')); // Returns Matt

echo evalstr('Hello {$user['name']}', array('user' => $this->GetAUser(123))); // Returns the 'user' objects 'GetAUser' methods 'name' property

re - Perl like Regular Expressions

The Re() function provides Regular Expression functionality in a Perl like way.

Simple matching

Determine if the string 'needle' exists in $haystack:

if (re('/needle/', $haystack)) {
    // Do something
}

Simple extraction

Extract a match from an input string

$haystack = 'foo bar baz quz quuz';
list($word) = re('/(qu.)/', $haystack);
echo $word; // Output: 'quz'

RE can also return only the first captured element by using the '1' modifier. The following code will act the same as the above but force the only match into a string rather than an array:

$haystack = 'foo bar baz quz quuz';
$word = re('/(qu.)/1', $haystack);
echo $word; // Output: 'quz'

Multiple extraction into an array

Extract multiple matches into an array

$haystack = 'foo bar baz quz quuz';
$words = re('/(ba.)/', $haystack);
print_r($words); // Output: array('bar', 'baz')

This is the same syntax as Simple Extraction. When multiple elements are found RE will return the elements as an array automatically.

Multiple extraction into variables

You can use PHP's list() function to automatically cram the output of RE into a series of variables.

$haystack = 'Matt is 28 years old';
list($name, $age) = re('/^(.+?) is ([0-9]+) years old$/', $haystack);

Simple substitution and replacement

Substitution (also known as replacement) is also supported.

$haystack = 'foo bar baz foo bar baz';
$output = re('s/bar/BAR/', $haystack);
echo $output; // Output: 'foo BAR baz foo bar baz'

By default only the first matching element is replaced. If you want to replace all matching items use the 'g' modifier:

$haystack = 'foo bar baz foo bar baz';
$output = re('s/bar/BAR/', $haystack);
echo $output; // Output: 'foo BAR baz foo BAR baz'

Substitution with back-references

Replace the words 'bar' and 'baz' into 'FOUND-r' and 'FOUND-z':

$haystack = 'foo bar baz';
$output = re('s/(ba.)/FOUND-\1/', $haystack);
echo $output; // Output: 'foo FOUND-bar FOUND-baz'

\1 and onwards is automatically set to the captured item.

Translation

Although not really used that much you can replace single characters based on a range:

$haystack = 'foo bar baz';
$output = re('tr/a-z/A-Z');
echo $output; // Output: 'FOO BAR BAZ'

Perl to PHP reference

This section contains some commonly used Perl syntax and the PHP equivelent when using this module. This is included because sometimes examples are more helpful than API waffle.

Example Perl PHP + Pherl
Extraction
$_ = 'foo bar baz';
($one, $two, $three) =~ m/(.*) .{3} .../;
$haystack = 'foo bar baz';
list($one, $two, $three) = re('m/(.*) .{3} .../', $haystack);
Subsitution
$_ = 'foo bar baz';
$new = s/foo/QUZ/;
$haystack = 'foo bar baz';
$new = re('s/foo/QUZ/', $haystack);
Translation
$_ = 'foo bar baz';
$new = tr/a-z/A-Z/;
$haystack = 'foo bar baz';
$new = re('tr/a-z/A-Z/', $haystack);

TODO


All versions of pherl with dependencies

PHP Build Version
Package Version
Requires php Version >=5.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hashbang/pherl contains the following files

Loading the files please wait ....