Recommend this page to a friend! |
Classes of Jorge Castro | Mapache Commons | README.md | Download |
|
DownloadMapache CommonsIt's a set of useful functions for PHP. The name is a pun (Mapache in spanish is "raccoon")
__Mapache Commons__ GoalsIt'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
CollectionIt's a class with a collection of functions related with arrays and lists. splitOpeningClosing> splitOpeningClosing($text,[$openingTag='('],[$closingTag=')'],[$startPosition=0],[$excludeEmpty=true],[$includeTag=false]) Split a string by an opening and closing tag and returns an array with the result. > splitOpeningClosing('hello(a,b,c)world(d,e,f)') > returns ['hello','a,b,c','world','d,e,f'] > splitOpeningClosing{'hello{a,b,c}world{d,e,f}','{','}') > returns ['hello','a,b,c','world','d,e,f'] > splitOpeningClosing('hello(a,b(,c)world(d,e,f)') > returns ['hello','a,b(,c','world','d,e,f'] splitNotStringSplit a string by ignoring parts of string where values are between " or '. > splitNotString($text,$separator,[$offset=0],[$excludeEmpty=true])
arrayChangeKeyCaseRecursiveIt changes the case (to lower or upper case) of the keys of an array recursively > arrayChangeKeyCaseRecursive($arr,$case=CASE_LOWER/CASE_UPPER)
arraySearchFieldIt returns the first (or all) key(s) inside an array/object in an array that matches the value of the field<br> For example, let's say the next array [
] And we want to find the first "name" equals to "mary"
> arraySearchField($array,$fieldName,$value)
isAssoc> isAssoc($array) Returns true if array is an associative array, false is it's an indexed array first> first($array) Returns the first element of an array. Sometimes the first element is not the index [0], for example ['key1'=>1,0=2] where the first element is 'key1' and not 0. This function always returns the right value. firstKey> firstKey($array) Returns the first key of an array. arrayKeyLower> arrayKeyLower($arr) Change the case of all the keys to lowercase arrayKeyUpper>arrayKeyUpper($arr) Change the case of all the keys to lowercase generateTable>generateTable($array,$css=true) Generate a html table from an array DebugIt's a class with a collection of functions related with debug. var_dump>var_dump($value,$console=false) Alternative to var_dump. It "pre" the result or it shows the result in the console of javascript. >var_dump($value,true) // returns a var_dump visible via the console of javascript (browser) WriteLog>WriteLog($logFile,$txt) It writes a log file and adds the txt to the log. If the log file is full (10mb) then it's emptied. TextIt's a class with a collection of functions related with strings. getArgument()> Text::getArgument($txt,[$set='='],[$trimValue=true]) Returns an array with the name of the argument and value (if any). It always returns a two dimension array > Example Text::getArgument('alpha=hello') > ['alpha','hello'] > Example Text::getArgument('alpha:hello',':') > ['alpha','hello'] strPosNotSpace()> Text::strPosNotSpace($txt,[$offset=0]) Returns the first position of a string that it's not a space
isUpper> isUpper($str) Returns true if the str is (completelly) uppercase isLower> isLower($str) Returns true if the str is (completelly) lowercase stripQuotes> stripQuotes($text) Strip quotes of a text (" or ') Example:
between> between($haystack, $startNeedle, $endNeedle,&$offset=0, $ignoreCase=false) Returns the text between two needles. > Text::between('Hello Brave World','Hello','World') // returns " Brave " replaceBetween> replaceBetween($haystack, $startNeedle, $endneedle, $replaceText, &$offset=0,$$replaceTag=false) Replace the text between two needles * If $replaceTag is true then it also replaces the $startNeedle and $endneedle > Text::replaceBetween('Hello Brave World','Hello','World',' Wayne ') // returns "Hello Wayne World" removeFirstChars> removeFirstChars($txt,$length=1) Remove the first character(s) for a string > Text::removeFirstChars('Hello') // returns "ello" removeLastChars> removeLastChars($txt,$length=1) Remove the last character(s) for a string > Text::removeLastChars('Hello') // returns "Hell" parseArgIt transforms a text = 'a1=1,a2=2' into an associative array. It uses the method parse_str() to do the conversion > parseArg($text, $separator = ',')
naturalArgIt 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. > naturalArg($text, $separator = ',')
camelCaseRetains the case of the text minus the first letter that it's converted in lowercase. Example:
strposArrayIt find the first (or last) ocurrence of a text. Unlikely strpos(), this method allows to find more than one neddle. > function strposArray($haystack, $needles,$offset=0,$last=false) Example:
removeParenthesisRemove the initial and final parenthesis but only if both matches. If the $start and $end arguments are arrays then both must have the same count and arrays are compared by pair of index Example:
hasParenthesisReturns true if it has both parenthesis. Example:
addParenthesisIt adds parenthesis only if the original input does not have it. Example:
Version list
LicenseApache-2.0. |