PHPackages                             eftec/mapache-commons - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. eftec/mapache-commons

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

eftec/mapache-commons
=====================

It's a set of useful functions for PHP. The name is a pun.

1.26(4mo ago)32.9kApache-2.0PHPPHP &gt;=7.4CI failing

Since Sep 18Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/EFTEC/mapache-commons)[ Packagist](https://packagist.org/packages/eftec/mapache-commons)[ Docs](https://github.com/EFTEC/mapache-commons)[ RSS](/packages/eftec-mapache-commons/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (1)Versions (25)Used By (0)

Mapache Commons
===============

[](#mapache-commons)

It's a set of useful functions for PHP. The name is a pun (Mapache in spanish is "raccoon")

[![Packagist](https://camo.githubusercontent.com/dcae5b9cf60f2967853242c47d6732c3a7ad8e4f267cfe8ad328948046954930/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65667465632f6d6170616368652d636f6d6d6f6e732e737667)](https://packagist.org/packages/eftec/mapache-commons)![Maintenance](https://camo.githubusercontent.com/eb3f3ffb1347bd1add4ab6d623131eaf8677d02e07107bad3ee7e7825d60e421/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032362e737667)![composer](https://camo.githubusercontent.com/7a6cce75e3353cd615b111f2f4ff50dec30cf814dddb88b2613f656cec298330/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6d706f7365722d253345322e302d626c75652e737667)![php](https://camo.githubusercontent.com/59558613d05bebac3748d4f75f0c94435dec5fb11d059b448c2d172e25d82120/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e342d677265656e2e737667)![php](https://camo.githubusercontent.com/5cd91a78fb469ca20b235b6951fb6dd77bda78ac4633eb432e93699bcb141589/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e342d677265656e2e737667)![CocoaPods](https://camo.githubusercontent.com/347353606ed8f26b45bcf9da083db0063fa1dadd1baef36a5f3bf9ce1d127548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d37302532352d79656c6c6f772e737667)

- [Mapache Commons](#mapache-commons)
    - [Goals](#goals)
    - [Families](#families)
    - [CollectionLib](#collectionlib)
        - [Method isAssoc()](#method-isassoc)
            - [Parameters:](#parameters)
        - [Method first()](#method-first)
            - [Parameters:](#parameters-1)
        - [Method firstKey()](#method-firstkey)
            - [Parameters:](#parameters-2)
        - [Method arrayKeyLower()](#method-arraykeylower)
            - [Parameters:](#parameters-3)
        - [Method arrayKeyUpper()](#method-arraykeyupper)
            - [Parameters:](#parameters-4)
        - [Method generateTable()](#method-generatetable)
            - [Parameters:](#parameters-5)
        - [Method splitOpeningClosing()](#method-splitopeningclosing)
            - [Parameters:](#parameters-6)
        - [Method splitNotString()](#method-splitnotstring)
            - [Parameters:](#parameters-7)
        - [Method arrayChangeKeyCaseRecursive()](#method-arraychangekeycaserecursive)
            - [Parameters:](#parameters-8)
        - [Method arraySearchField()](#method-arraysearchfield)
            - [Parameters:](#parameters-9)
        - [Method xmlToString()](#method-xmltostring)
            - [Parameters:](#parameters-10)
        - [Method arrayToXML()](#method-arraytoxml)
            - [Parameters:](#parameters-11)
        - [Method stringToXML()](#method-stringtoxml)
            - [Parameters:](#parameters-12)
        - [Method xmlToArray()](#method-xmltoarray)
            - [Parameters:](#parameters-13)
    - [DebugLib](#debuglib)
        - [Method var\_dump()](#method-var_dump)
            - [Parameters:](#parameters-14)
        - [Method WriteLog()](#method-writelog)
            - [Parameters:](#parameters-15)
    - [TextLib](#textlib)
        - [Method isUpper()](#method-isupper)
            - [Parameters:](#parameters-16)
        - [Method isLower()](#method-islower)
            - [Parameters:](#parameters-17)
        - [Method between()](#method-between)
            - [Parameters:](#parameters-18)
        - [Method stripQuotes()](#method-stripquotes)
            - [Parameters:](#parameters-19)
        - [Method removeParenthesis()](#method-removeparenthesis)
            - [Parameters:](#parameters-20)
        - [Method replaceBetween()](#method-replacebetween)
            - [Parameters:](#parameters-21)
        - [Method removeFirstChars()](#method-removefirstchars)
            - [Parameters:](#parameters-22)
        - [Method removeLastChars()](#method-removelastchars)
            - [Parameters:](#parameters-23)
        - [Method getArgument()](#method-getargument)
            - [Parameters:](#parameters-24)
        - [Method strPosNotSpace()](#method-strposnotspace)
            - [Parameters:](#parameters-25)
        - [Method strposArray()](#method-strposarray)
            - [Parameters:](#parameters-26)
        - [Method parseArg()](#method-parsearg)
            - [Parameters:](#parameters-27)
        - [Method parseArg2()](#method-parsearg2)
            - [Parameters:](#parameters-28)
        - [Method naturalArg()](#method-naturalarg)
            - [Parameters:](#parameters-29)
        - [Method str\_replace\_ex()](#method-str_replace_ex)
            - [Parameters:](#parameters-30)
        - [Method wildCardComparison()](#method-wildcardcomparison)
            - [Parameters:](#parameters-31)
        - [Method endsWith()](#method-endswith)
            - [Parameters:](#parameters-32)
        - [Method replaceCurlyVariable()](#method-replacecurlyvariable)
            - [Parameters:](#parameters-33)
        - [Method addParenthesis()](#method-addparenthesis)
            - [Parameters:](#parameters-34)
        - [Method hasParenthesis()](#method-hasparenthesis)
            - [Parameters:](#parameters-35)
        - [Method camelCase()](#method-camelcase)
            - [Parameters:](#parameters-36)
    - [FileLib](#filelib)
        - [Field lastError ()](#field-lasterror-)
        - [Method getDirFiles()](#method-getdirfiles)
            - [Parameters:](#parameters-37)
        - [Method getDirFirstFile()](#method-getdirfirstfile)
            - [Parameters:](#parameters-38)
        - [Method getDirFolders()](#method-getdirfolders)
            - [Parameters:](#parameters-39)
        - [Method getExtensionPath()](#method-getextensionpath)
            - [Parameters:](#parameters-40)
        - [Method getFileNamePath()](#method-getfilenamepath)
            - [Parameters:](#parameters-41)
        - [Method getBaseNamePath()](#method-getbasenamepath)
            - [Parameters:](#parameters-42)
        - [Method getDirPath()](#method-getdirpath)
            - [Parameters:](#parameters-43)
        - [Method fixUrlSeparator()](#method-fixurlseparator)
            - [Parameters:](#parameters-44)
        - [Method safeFileGetContent()](#method-safefilegetcontent)
            - [Parameters:](#parameters-45)
        - [Method safeFilePutContent()](#method-safefileputcontent)
            - [Parameters:](#parameters-46)
        - [Method isAbsolutePath()](#method-isabsolutepath)
            - [Parameters:](#parameters-47)
    - [Version list](#version-list)
    - [License](#license)

[![Mapache Commons](docs/raccoon_small.png)](docs/raccoon_small.png)
**Mapache Commons**

Goals
-----

[](#goals)

It's a set of useful function with the next requirements:

- The function mustn't have dependencies (unless it requires a php module).
- The function must be FAST and memory friendly over the syntax sugar.
- The function must be able to run statically, and it must be self-contained.
- The function must be generic, and it must solve generic problems. For example, a function that calculates the VAT of a specific country is not allowed.

Families
--------

[](#families)

- CollectionLib
- TextLib
- DebugLib

CollectionLib
-------------

[](#collectionlib)

Class CollectionLib

### Method isAssoc()

[](#method-isassoc)

Returns true if array is an associative array, false is it's an indexed array
**Example:**

```
$isAssoc=CollectionLib::isAssoc($array); // slow, more precise.
$isAssoc=CollectionLib::isAssoc($array,true); // fast, less precise

```

#### Parameters:

[](#parameters)

- **$array** input array (array)

### Method first()

[](#method-first)

Returns the first element of an array.
Sometimes the first element is not the index \[0\], for example \['key1'=&gt;1,0=2\] where the first element is 'key1' and not 0. This function always returns the right value.

#### Parameters:

[](#parameters-1)

- **$array** input array (array)

### Method firstKey()

[](#method-firstkey)

Returns the first key of an array.

#### Parameters:

[](#parameters-2)

- **$array** input array (array)

### Method arrayKeyLower()

[](#method-arraykeylower)

Change the case of the key to lowercase

#### Parameters:

[](#parameters-3)

- **$array** input array (array)

### Method arrayKeyUpper()

[](#method-arraykeyupper)

Change the case of the key to lowercase

#### Parameters:

[](#parameters-4)

- **$array** input array (array)

### Method generateTable()

[](#method-generatetable)

Generate a html table from an array

#### Parameters:

[](#parameters-5)

- **$array** input array (array|null)
- **$css** if true then it uses the build in style. If false then it doesn't use style. If string then it uses as class (string|bool)

### Method splitOpeningClosing()

[](#method-splitopeningclosing)

Split a string using an opening and closing tag, by default "(" and ")".
Example:

```
CollectionLib::splitOpeningClosing("a(B,C,D)e(F,G,H)"); // ['a','B,C,D','e','F,G,H']
CollectionLib::splitOpeningClosing("a(B,C,D)e(F,G,H)i"); // ['a','B,C,D','e','F,G,H','i']

```

#### Parameters:

[](#parameters-6)

- **$text** input text to separated (string)
- **$openingTag** Opening tag, default "(" (string)
- **$closingTag** closing tag, default ")" (string)
- **$startPosition** start position (by default it is zero) (int)
- **$excludeEmpty** if true then it excludes all empty values. (bool)
- **$includeTag** if true then it includes the tag. (bool)

### Method splitNotString()

[](#method-splitnotstring)

Split a string by ignoring parts of string where values are between " or '.
Example:

```
CollectionLib::splitNotString('a,b,"CC,D,E",e,f' ,","); // ['a','b','CC,D,E','e','f']

```

#### Parameters:

[](#parameters-7)

- **$text** input text (string)
- **$separator** param string $separator (string)
- **$offset** param int $offset (int)
- **$excludeEmpty** param bool $excludeEmpty (bool)

### Method arrayChangeKeyCaseRecursive()

[](#method-arraychangekeycaserecursive)

It changes the case (to lower or upper case) of the keys of an array recursively
**Example:**

```
$arr=['A'=>'a','b'=>'b'];
CollectionLib::arrayChangeKeyCaseRecursive($arr);
// returns ['a'=>'a','b'=>'b']
CollectionLib::arrayChangeKeyCaseRecursive($arr,true);
// returns ['A'=>'a','B'=>'b']

```

#### Parameters:

[](#parameters-8)

- **$array** input array (array)
- **$case** \[optional\] by default is CASE\_LOWER Either CASE\_UPPER or CASE\_LOWER (default)

     (int)

### Method arraySearchField()

[](#method-arraysearchfield)

It returns the first (or all) key(s) inside an array/object in an array that matches the value of the field
**Example:**

```
$array=[['name'=>'john'],['name'=>'mary']];
CollectionLib::arraySearchField($array,'name','mary'); // 1
CollectionLib::arraySearchField([(object)['name'=>'john'],(object)['name'=>'mary']],'name','mary'); // 1
CollectionLib::arraySearchField([['name'=>'john'],['name'=>'mary'],['name'=>'mary']],'name','mary',true); // returns [1,2]

```

#### Parameters:

[](#parameters-9)

- **$array** input array (array)
- **$fieldName** name of index of the field (string|int)
- **$value** value to search (mixed)
- **$returnAll** if true then it returns all matches. If false it returns the first value. (bool)

### Method xmlToString()

[](#method-xmltostring)

It converts a xml (SimpleXMLElement object) into a string
**Example:**

```
$string=CollectionLib::xmlToString($xml,true); // "..."

```

#### Parameters:

[](#parameters-10)

- **$xml** param SimpleXMLElement $xml (SimpleXMLElement)
- **$format** if true then the result is formatted. (bool)

### Method arrayToXML()

[](#method-arraytoxml)

It convers an array into a xml (SimpleXMLElement object) **Example:**

```
$xml=CollectionLib::arrayToXML($array,'root'); // ...

```

#### Parameters:

[](#parameters-11)

- **$data** param array $data (array)
- **$rootName** The name of the root tag (default root) (string)
- **$insidetag** It is used to fix a specific condition with the xml generated by PHP. (string)

### Method stringToXML()

[](#method-stringtoxml)

It converts a string into a xml (SimpleXMLElement object) using simplexml\_load\_string including a fix
**Example:**

```
$xml=CollectionLib::stringToXML('ab');

```

#### Parameters:

[](#parameters-12)

- **$string** the value to convert (string)
- **$className** param null $className (null)
- **$options** libxml options (int)
- **$insidetag** by default is 'value\_inside'. In some cases, the parser fails to generate an XML attribute when the child is empty 2. The solution is to generate a new tag &lt;\_value&gt;2&lt;/\_value&gt; (string)

### Method xmlToArray()

[](#method-xmltoarray)

It converts an XML class (SimpleXMLElement object) into an array. **Example:**

```
$array=CollectionLib::xmlToArray($xml);

```

#### Parameters:

[](#parameters-13)

- **$xml** param SimpleXMLElement $xml (SimpleXMLElement)

DebugLib
--------

[](#debuglib)

Class Debug

### Method var\_dump()

[](#method-var_dump)

Alternative to var\_dump. It "pre" the result or it shows the result in the console of javascript.
**Example:**

```
DebugLib::var_dump($value,true); // returns a var_dump visible via the console of javascript (browser)

```

#### Parameters:

[](#parameters-14)

- **$value** param $value ()
- **$type** : 0=normal (```
    ), 1=javascript console, 2=table (use future) (int)
    ```
- **$returnValue** param bool $returnValue (bool)

### Method WriteLog()

[](#method-writelog)

Write a log file. If the file is over 10mb then the file is resetted.

```
DebugLib::WriteLog('somefile.txt','warning','it is a warning');
DebugLib::WriteLog('somefile.txt','it is a warning');

```

#### Parameters:

[](#parameters-15)

- **$logFile** The file to write (string)
- **$level** The level of the message, example "error", "info", 1, etc. (mixed)
- **$txt** if txt is empty then level is defined as warning and level is used for the description (string|object|array)

TextLib
-------

[](#textlib)

Class TextLib

### Method isUpper()

[](#method-isupper)

Returns true if the str is (completelly) uppercase

#### Parameters:

[](#parameters-16)

- **$str** Input text (string)

### Method isLower()

[](#method-islower)

Returns true if the str is (completelly) lowercase

#### Parameters:

[](#parameters-17)

- **$str** param $str ()

### Method between()

[](#method-between)

Obtain a string between one text and other. **Example:**

```
TextLib::between('Hello Brave World','Hello','World');  // returns " Brave "
TextLib::between('mary has a lamb','has','lamb') // returns ' a '

```

#### Parameters:

[](#parameters-18)

- **$haystack** param string $haystack (string)
- **$startNeedle** The initial text to search
    if empty then it starts at the start of the haystack. (string)
- **$endNeedle** The end tag to search
    if empty then it ends at the end of the haystack (string)
- **$offset** param null|int $offset (null|int)
- **$ignoreCase** param bool $ignoreCase (bool)

### Method stripQuotes()

[](#method-stripquotes)

Strip quotes of a text " or ' if the value in between quotes
If the value is not quoted then it is not touched.
If the value is not correctly closed ("hello or "hello' ), then the quota is not removed.
The value is trimmed ' "hello world"' --&gt; 'hello world'
**Example:**

```
TextLib::stripQuotes('"hello world"');
// returns hello world

```

#### Parameters:

[](#parameters-19)

- **$text** param $text ()

### Method removeParenthesis()

[](#method-removeparenthesis)

Remove the initial and final parenthesis but only if both matches.
If the $start and $end are arrays then both must have the same count and arrays are compared by pair of index
**Example:**

```
TextLib::removeParenthesis('hello'); // return "hello";
TextLib::removeParenthesis('(hello)'); // return "hello";
TextLib::removeParenthesis('[hello]'
,['(','{','[']
,[')','}',']']); // returns "hello"
TextLib::removeParenthesis("'hello'"
,"'"
,"'"); // returns "hello"

```

#### Parameters:

[](#parameters-20)

- **$txt** Input value. Example "hello", "(hello)" (string)
- **$start** the open parenthesis, by default it's '('. (string|array)
- **$end** the close parenthesis, by default it's ')'. (string|array)

### Method replaceBetween()

[](#method-replacebetween)

Replace the text between two needles
**Example:**

```
TextLib::replaceBetween('Hello Brave World','Hello','World',' Wayne ') // returns "Hello Wayne World"

```

#### Parameters:

[](#parameters-21)

- **$haystack** the input value (string)
- **$startNeedle** The initial text to search
    if empty then it starts at the start of the haystack. (string)
- **$endNeedle** The end tag to search
    if empty then it ends at the end of the haystack (string)
- **$replaceText** Text to replace (string)
- **$offset** the offset position to start the search. (null|int)
- **$replaceTag** If true then it also replaces the tags (bool)

### Method removeFirstChars()

[](#method-removefirstchars)

Remove the first character(s) for a string
**Example:**

```
TextLib::removeFirstChars('Hello') // returns "ello"

```

#### Parameters:

[](#parameters-22)

- **$str** The input text (string)
- **$length** The amount of characters to remove (default 1) (int)

### Method removeLastChars()

[](#method-removelastchars)

Remove the last character(s) for a string
**Example:**

```
TextLib::removeLastChars('Hello') // returns "Hell"

```

#### Parameters:

[](#parameters-23)

- **$str** The input text (string)
- **$length** The amount of characters to remove (default 1) (int)

### Method getArgument()

[](#method-getargument)

It separates an argument from the value to the set value.
Returns an array with the name of the argument and value (if any). It always returns a two dimension array **Example:**

```
self::getArgument("arg=200"); // returns ["arg","200"]
self::getArgument("arg:200",':'); // returns ["arg","200"]

```

#### Parameters:

[](#parameters-24)

- **$str** The input text (string)
- **$set** The separator of operator (string)
- **$trimValue** param bool $trimValue (bool)

### Method strPosNotSpace()

[](#method-strposnotspace)

It returns the first non-space position inside a string. **Example:**

```
TextLib::strPosNotSpace('   abc  def'); // returns 3

```

#### Parameters:

[](#parameters-25)

- **$str** input string (string)
- **$offset** offset position (int)
- **$charlist** list of characters considered as space (string)

### Method strposArray()

[](#method-strposarray)

It finds the first (or last) ocurrence of a text.
Unlikely strpos(), this method allows finding more than one neddle.
**Example:**

```
TextLib::strposArray('a,b.d.e,f.g',['x','t','.']); // return 3
TextLib::strposArray('a,b.d.e,f.g',['x','t',','],0,true); // return 7

```

#### Parameters:

[](#parameters-26)

- **$haystack** the input value (string)
- **$needles** the value (or values) to find (string|array)
- **$offset** the offset position (initially it's 0) (int)
- **$last** if false (default) it returns the first ocurrence. If true returns the last one (bool)

### Method parseArg()

[](#method-parsearg)

It transforms a text = 'a1=1,a2=2' into an associative array
It uses the method parse\_str() to do the conversion
**Note:** It doesn't work with quotes or double quotes. a1="aa,bb",bb=30 doesn't work **Example:**

```
TextLib::parseArg('a=1,b=1'); // returns ['a'=>'1','b'=>'1']

```

#### Parameters:

[](#parameters-27)

- **$text** The input string with the initial values (string)
- **$separator** The separator (string)

### Method parseArg2()

[](#method-parsearg2)

It's the same than parseArg() but it's x3 times slower.
It also considers quotes and doubles quotes.
Example:

```
TextLib::parseArg2("a1=1,a2=2,a3="aa,bb"); // ["a1"=>1,"a2"=>2,"a3"=>""aa,bb""]
TextLib::parseArg("a1=1,a2=2,a3="aa,bb"); // ["a1"=>1,"a2"=>2,"a3"=>""aa","bb""=>""]

```

#### Parameters:

[](#parameters-28)

- **$text** The input string with the initial values (string)
- **$separator** The separator. It does not separates text inside quotes or double-quotes. (string)

### Method naturalArg()

[](#method-naturalarg)

It parses a natural string and returns a declarative array
A "natural string", it is a set of values or arguments separated by space , where a value is the index and the new one is the value of the index.

```
TextLib::naturalArg('select * from table where 1=1'
,['select'=>'req','from'=>'req','where'=>'opt']);
// returns ['select'=>'*','from'=>'table','where'=>'1=1']
TextLib::naturalArg('item export table inport file'
,['item'=>'first','export'=>'opt','inport'=>'opt']);
// returns: ['item' => 'item', 'export' => 'table', 'inport' => 'file']

```

#### Parameters:

[](#parameters-29)

- **$txt** the input value. Example "somevalue TYPE int LENGHT 30" (string)
- **$separators** the indicator for each field.
    first = indicates the first element (optional)
    opt = indicates the field is optional
    req = indicates the field is required
     (array)

### Method str\_replace\_ex()

[](#method-str_replace_ex)

It works as str\_replace, but it also allows to limit the number of replacements.

#### Parameters:

[](#parameters-30)

- **$search** param string $search (string)
- **$replace** param string $replace (string)
- **$subject** param string $subject (string)
- **$limit** param int $limit (int)

### Method wildCardComparison()

[](#method-wildcardcomparison)

It compares with wildcards (\*) and returns true if both strings are equals
The wildcards only works at the beginning or at the end of the string.
**Example:**

****```
TextLib::wildCardComparison('abcdef','abc*'); // true
TextLib::wildCardComparison('abcdef','*def'); // true
TextLib::wildCardComparison('abcdef','*abc*'); // true
TextLib::wildCardComparison('abcdef','*cde*'); // true
TextLib::wildCardComparison('abcdef','*cde'); // false

```

#### Parameters:

[](#parameters-31)

- **$text** param string $text (string)
- **$textWithWildcard** param string|null $textWithWildcard (string|null)

### Method endsWith()

[](#method-endswith)**** it returns true if $string ends with $endString
**Example:**

****```
TextLib::endsWidth('hello world','world'); // true

```

#### Parameters:

[](#parameters-32)

- **$string** param $string ()
- **$endString** param $endString ()

### Method replaceCurlyVariable()

[](#method-replacecurlyvariable)**** Replaces all variables defined between {{ }} by a variable inside the dictionary of values.
Example:
replaceCurlyVariable('hello={{var}}',\['var'=&gt;'world'\]) // hello=world
replaceCurlyVariable('hello={{var}}',\['varx'=&gt;'world'\]) // hello=
replaceCurlyVariable('hello={{var}}',\['varx'=&gt;'world'\],true) // hello={{var}}

#### Parameters:

[](#parameters-33)

- **$string** The input value. It could contain variables defined as {{namevar}} (string)
- **$values** The dictionary of values. (array)
- **$notFoundThenKeep** \[false\] If true and the value is not found, then it keeps the value. Otherwise, it is replaced by an empty value (bool)

### Method addParenthesis()

[](#method-addparenthesis)

It adds a parenthesis (or other symbol) at the start and end of the text. If it already has it, then it is not added.
**Example:**

```
TextLib::addParenthesis('hello'); // return '(hello)';
TextLib::addParenthesis('(hello)');// return '(hello)';

```

#### Parameters:

[](#parameters-34)

- **$txt** Input value. Example "hello", "(hello)" (string)
- **$start** the open parenthesis, by default it's '('. (string|array)
- **$end** the close parenthesis, by default it's ')'. (string|array)

### Method hasParenthesis()

[](#method-hasparenthesis)

It returns true if the text has an open and ending parenthesis (or other symbol).
**Example:**

```
TextLib::hasParenthesis('hello'); // return false;
TextLib::hasParenthesis('(hello)'); // return true;

```

#### Parameters:

[](#parameters-35)

- **$txt** Input value. Example "hello", "(hello)" (string)
- **$start** the open parenthesis, by default it's '('. (string|array)
- **$end** the close parenthesis, by default it's ')'. (string|array)

### Method camelCase()

[](#method-camelcase)

Retains the case minus the first letter that it's converted in lowercase
If the text contains the characters "*" or " ", then the next character is uppercase
If the text does not contain any character "*" or " ", then only the first character is replaced. **Example:**

```
TextLib::camelCase('HelloWorld'); // return "helloWorld";
TextLib::camelCase('hello_world'); // return "helloWorld";

```

#### Parameters:

[](#parameters-36)

- **$txt** input value (string)

FileLib
-------

[](#filelib)

Class Files
This class has a collection of functions to interact with files and directories.

### Field lastError ()

[](#field-lasterror-)

### Method getDirFiles()

[](#method-getdirfiles)

It gets the content (files) of a directory. It does not include other directories.

#### Parameters:

[](#parameters-37)

- **$dir** The directory to scan. (string)
- **$extensions** The extension to find (without dot). \['\*'\] means any extension. (array)
- **$recursive** if true (default), then it scans the folders recursively. (bool)

### Method getDirFirstFile()

[](#method-getdirfirstfile)

It returns the first file (exclude directories) find in a directory that matches a specific extension(s)
The order of the extensions could count.
If there are two files with the same extension, then it returns the first one.

#### Parameters:

[](#parameters-38)

- **$dir** The directory to scan. (string)
- **$extensions** The extension to find (without dot). \['\*'\] means any extension. (array)
- **$sort** (default false), if true then it sorts the list previous the filter. (bool)
- **$descending** (default false), if true then it sorts (if enable) descending. (bool)

### Method getDirFolders()

[](#method-getdirfolders)

It gets the content (folders) of a directory without trailing slash. It does not include files.

#### Parameters:

[](#parameters-39)

- **$dir** The directory to scan. (string)
- **$recursive** if true (default), then it scans the folders recursively. (bool)

### Method getExtensionPath()

[](#method-getextensionpath)

It gets the extension of a file (without dot). If the file has no extension then it returns empty.

#### Parameters:

[](#parameters-40)

- **$fullPath** the path to analize. (string)

### Method getFileNamePath()

[](#method-getfilenamepath)

It gets the filename (without extension and directory)

#### Parameters:

[](#parameters-41)

- **$fullPath** the path to analize. (string)

### Method getBaseNamePath()

[](#method-getbasenamepath)

It gets the base name (filename with extension). It does not include the directory.

#### Parameters:

[](#parameters-42)

- **$fullPath** the path to analize. (string)

### Method getDirPath()

[](#method-getdirpath)

It gets the dir from a full path (without trailing slash)

#### Parameters:

[](#parameters-43)

- **$fullPath** the path to analize. (string)

### Method fixUrlSeparator()

[](#method-fixurlseparator)

It fixes the path by converting the slash and inverse lash into the system folder separator

#### Parameters:

[](#parameters-44)

- **$fullPath** the path to analize. (string)

### Method safeFileGetContent()

[](#method-safefilegetcontent)

It gets the content of a file. It never throws an exception
In case of error, it returns the default value

#### Parameters:

[](#parameters-45)

- **$filename** The filename to open. (string)
- **$use\_include\_path** used to trigger include path search. (bool)
- **$context** A valid context resource created with (null)
- **$offset** The offset where the reading starts. (int)
- **$length** Maximum length of data read. The default is to read until end of file is reached. (int|null)
- **$default** The value to return if it is unable to open the file (null|mixed)

### Method safeFilePutContent()

[](#method-safefileputcontent)

Write a string to a file. This operator is safe, it never throws an exception.

#### Parameters:

[](#parameters-46)

- **$filename** Path to the file where to write the data. (string)
- **$data** The data to write. Can be either a string, an array or a stream resource. (mixed)
- **$flag** The value of flags can be any combination of the following flags, with some restrictions, joined with the binary OR (|) operator. (int)
- **$context** A valid context resource created with stream\_context\_create. (mixed)
- **$tries** The number of tries (default 3). Every try has a delay of 300ms. (int)

### Method isAbsolutePath()

[](#method-isabsolutepath)

Returns true if the path is absolute, otherwise it returns false.
This function works in Linux and Windows (and most probably in other UNIX OS)

#### Parameters:

[](#parameters-47)

- **$fullPath** The path to analize. (string)

Version list
------------

[](#version-list)

- 1.26 2026-01-01
    - updated WebLib
- 1.25 2025-10-07
    - updated argument types.
- 1.24
    - Fixed an exception with FileLib. It also stores every error in a field.
    - Completed README.md
    - Cleaned PHPDocs.
- 1.23 Modified .gitattributes and .gitignore to streamline the final version.
- 1.22 The next classes have been renamed:
    - Text (deprecated) =&gt; TextLib
    - Collection (deprecated) =&gt; CollectionLib
    - Debug (deprecated) =&gt; DebugLib
    - It is because there are a dozen of libraries who use the same name for the classes.
    - **You can still use the same library without changes** but for new code I suggest to use the new names.
    - \[new\] FileLib::getDirFirstFile()
- 1.21 added FileLib class
    - getDirFiles()
    - getDirFolders()
    - getExtensionPath()
    - getDirPath()
    - getBaseNamePath()
    - getFileNamePath()
    - fixUrlSeparator()
    - safeFileGetContent()
    - safeFilePutContent()
    - isAbsolutePath()
- 1.20 New methods CollectionLib::xmlToString,CollectionLib::arrayToXML,CollectionLib::stringToXML,CollectionLib::xmlToArray
- 1.17 New Method TextLib::str\_replace\_ex()
- 1.16 New methods TextLib::wildcardComparison() and TextLib::endsWith()
- 1.15 New method TextLib::parseArg2()
- 1.14 TextLib::camelCase() solved a small bug
- 1.13 TextLib::replaceCurlyVariable() updated
- 1.12
    - Collection:splitOpeningClosing added argument $includeTag
- 1.11
    - TextLib::replaceCurlyVariable Added method
- 1.10
    - TextLib::strPosNotSpace() added argument $charlist
- 1.9 2019-12-09
    - TextLib::replacetext() it does not crash if the end tag is missing.
    - TextLib::replacetext() it as a new argument
- 1.8 2019-12-04
    - TextLib::between() now allows empty $startNeedle and $endNeedle
- 1.7 2019-12-04 new methods
    - TextLib::addParenthesis()
    - TextLib::hasParenthesis()
- 1.6 2019-12-04 new methods
    - TextLib::parseArg()
    - TextLib::naturalArg()
    - TextLib::strposArray()
    - TextLib::camelCase()
    - TextLib::removeParenthesis()
    - CollectionLib::arrayChangeKeyCaseRecursive()
    - CollectionLib::arraySearchField()
- 1.5 2019-03-10 new functions:
    Collection:splitOpeningClosing()
    TextLib::strPosNotSpace()
    TextLib::getArgument()
    CollectionLib::splitNotString()
- 1.4 2019-02-16 New functions TextLib::removeFirstChars(),TextLib::removeLastChars()
- 1.3 2019-02-16 Added new methods and Unit test.
- 1.2 2018-10-27 Some changes in the class collection.
- 1.0 2018-09-18 First version

License
-------

[](#license)

Apache-2.0.

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance75

Regular maintenance activity

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 80.4% 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 ~115 days

Recently: every ~127 days

Total

24

Last Release

133d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bf6ba9d7f6f6c3ecde2779a29e1a4948f0f338c074ddceb3fbeb79c6dd1e68c?d=identicon)[JorgeCastro](/maintainers/JorgeCastro)

---

Top Contributors

[![jorgecc](https://avatars.githubusercontent.com/u/9570242?v=4)](https://github.com/jorgecc "jorgecc (41 commits)")[![jorgecc-business-account](https://avatars.githubusercontent.com/u/12418702?v=4)](https://github.com/jorgecc-business-account "jorgecc-business-account (10 commits)")

---

Tags

collectiondebugphpphp-librarytextphpdebugcollectiontext

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eftec-mapache-commons/health.svg)

```
[![Health](https://phpackages.com/badges/eftec-mapache-commons/health.svg)](https://phpackages.com/packages/eftec-mapache-commons)
```

###  Alternatives

[werxe/laravel-collection-macros

Custom Laravel Collection macros.

2625.8k](/packages/werxe-laravel-collection-macros)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[jshannon63/jsoncollect

Supercharge your JSON using collections

154.9k1](/packages/jshannon63-jsoncollect)

PHPackages © 2026

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