- Install
- Introduction
- API
- addslashes
- bin2hex
- chunkSplit
- convertUudecode
- convertUuencode
- countChars
- crypt
- explode
- hex2bin
- htmlEntityDecode
- htmlentities
- htmlspecialchars
- htmlspecialcharsDecode
- ireplace
- istr
- lcfirst
- len
- ltrim
- md5
- nl2br
- pad
- pbrk
- pos
- pregReplace
- quotedPrintableDecode
- quotedPrintableEncode
- quotemeta
- repeat
- replace
- rev
- rot13
- rtrim
- sha1
- shuffle
- sprintf
- str
- stripTags
- stripcslashes
- stripslashes
- substr
- substrCompare
- substrCount
- substrReplace
- tok
- tolower
- toupper
- tr
- trim
- ucfirst
- ucwords
- vsprintf
- wordwrap
- Contributing
====
composer install eden/string
====
The following documentation uses eden()
in its example reference. Enabling this function requires an extra step as descirbed in this section which is not required if you access this package using the following.
Eden_String_Index::i();
When using composer, there is not an easy way to access functions from packages. As a workaround, adding this constant in your code will allow eden()
to be available after.
Eden::DECORATOR;
For example:
Eden::DECORATOR;
eden()->inspect('Hello World');
====
Chainable string methods. When using multiple PHP string functions in one line, it makes code harder to read. This is because a programmer needs to be trained to read code from inner to outer, rather than traditionally left to right (unless you live in Japan). Eden's data typing are objects that correct this readability problem.
str_replace('L', 'y', strtoupper(substr('hello', 1, 3))); // Eyy
The above demonstrates that we must read this as substr()
, then strtoupper()
, followed by str_replace()
which is inner function first going outwards. The example below shows how using types makes this line easier to read.
echo eden('string')->set('hello')->substr(1, 3)->toupper()->replace('L', 'y'); //--> Eyy
Expressed vertically as below shows something more pleasing to a developer.
echo eden('string')
->set('hello')
->substr(1, 3)
->toupper()
->replace('L', 'y'); //--> Eyy
When echoed the string object will automatically convert to a native string. Eden covers most of the string functions provided by PHP. Below is a list of string methods you can linearly perform.
====
====
Same as PHP: addslashes
eden('string')->addslashes();
eden('string')->set('Hel"\'lo')->addslashes();
====
Same as PHP: bin2hex
eden('string')->bin2hex();
eden('string')->set('01010100100')->bin2hex();
====
Same as PHP: chunk_split
eden('string')->chunkSplit(int $length, string $separator);
eden('string')->set('Hello')->chunkSplit(2, ':');
====
Same as PHP: convert_uudecode
eden('string')->convertUudecode();
eden('string')->set('%2&5L;&\`\n`\n')->convertUudecode();
====
Same as PHP: convert_uuencode
eden('string')->convertUuencode();
eden('string')->set('Hello')->convertUuencode();
====
Same as PHP: count_chars
eden('string')->countChars(int $min_length);
eden('string')->set('Hello')->countChars(1);
====
Same as PHP: crypt
eden('string')->crypt(string $salt);
eden('string')->set('Hello')->crypt('123');
====
Same as PHP: explode
eden('string')->explode(string $separator[,int $limit]);
eden('string')->set('1-2-3-4')->explode('-');
====
Same as PHP: hex2bin
eden('string')->hex2bin();
eden('string')->set('3031303130313030313030')->hex2bin();
====
Same as PHP: html_entity_decode
eden('string')->htmlEntityDecode();
eden('string')->set('&')->htmlEntityDecode();
====
Same as PHP: htmlentities
eden('string')->htmlentities();
eden('string')->set('&')->htmlentities();
====
Same as PHP: htmlspecialchars
eden('string')->htmlspecialchars();
eden('string')->set('&')->htmlspecialchars();
====
Same as PHP: htmlspecialchars_decode
eden('string')->htmlspecialcharsDecode();
eden('string')->set('&')->htmlspecialcharsDecode();
====
Same as PHP: lcfirst
eden('string')->lcfirst();
eden('string')->set('Hello')->lcfirst();
====
Same as PHP: ltrim
eden('string')->ltrim();
eden('string')->set(' Hello')->ltrim();
====
Same as PHP: md5
eden('string')->md5();
eden('string')->set('Hello')->md5();
====
Same as PHP: nl2br
eden('string')->nl2br();
eden('string')->set("Hel\nlo")->nl2br();
====
Same as PHP: preg_replace
eden('string')->pregReplace(string $regex, string $replacement);
eden('string')->set('Hello')->pregReplace('/e/', 'i');
====
Same as PHP: quoted_printable_decode
eden('string')->quotedPrintableDecode();
eden('string')->set('Hello')->quotedPrintableDecode();
====
Same as PHP: quoted_printable_encode
eden('string')->quotedPrintableEncode();
eden('string')->set('Hello')->quotedPrintableEncode();
====
Same as PHP: quotemeta
eden('string')->quotemeta();
eden('string')->set('Hello')->quotemeta();
====
Same as PHP: rtrim
eden('string')->rtrim();
eden('string')->set('Hello ')->rtrim();
====
Same as PHP: sha1
eden('string')->sha1();
eden('string')->set('Hello')->sha1();
====
Same as PHP: sprintf
eden('string')->sprintf([mixed $variable[, mixed $variable2 ..]]);
eden('string')->set('Hello %s')->sprintf('You');
====
Same as PHP: str_ireplace
eden('string')->ireplace(string $needle, string $replacement);
eden('string')->set('Hello')->ireplace('l', 'y');
====
Same as PHP: str_pad
eden('string')->pad(int $length, string $replacement);
eden('string')->set('Hello')->pad(7, 'o');
====
Same as PHP: str_repeat
eden('string')->repeat(int $multiplier);
eden('string')->set('Hello')->repeat(3);
====
Same as PHP: str_replace
eden('string')->replace(string $needle, string $replacement);
eden('string')->set('Hello')->replace('l', 'y');
====
Same as PHP: str_rot13
eden('string')->rot13();
eden('string')->set('Hello')->rot13();
====
Same as PHP: str_shuffle
eden('string')->shuffle();
eden('string')->set('Hello')->shuffle();
====
Same as PHP: strip_tags
eden('string')->stripTags([string $allowableTags]);
eden('string')->set('H<b>e</b>llo')->stripTags();
====
Same as PHP: stripcslashes
eden('string')->stripcslashes();
eden('string')->set('Hello')->stripcslashes();
====
Same as PHP: stripslashes
eden('string')->stripslashes();
eden('string')->set('He\\llo')->stripslashes();
====
Same as PHP: stristr
eden('string')->istr(string $needle);
eden('string')->set('Hello')->istr('e');
====
Same as PHP: strlen
eden('string')->len();
eden('string')->set('Hello')->len();
====
Same as PHP: strpbrk
eden('string')->pbrk(string $needle);
eden('string')->set('Hello')->pbrk('abcdefgh');
====
Same as PHP: strpos
eden('string')->pos(string $needle);
eden('string')->set('Hello')->pos('e');
====
Same as PHP: strrev
eden('string')->rev();
eden('string')->set('Hello')->rev();
====
Same as PHP: strstr
eden('string')->str(string $needle);
eden('string')->set('Hello')->str('e');
====
Same as PHP: strtok
eden('string')->tok(string $needle);
eden('string')->set('Hello')->tok('e');
====
Same as PHP: strtolower
eden('string')->tolower();
eden('string')->set('Hello')->tolower();
====
Same as PHP: strtoupper
eden('string')->toupper();
eden('string')->set('Hello')->toupper();
====
Same as PHP: strtr
eden('string')->tr(string $needle, string $replacement);
eden('string')->set('Hello')->tr('e', 'y');
====
Same as PHP: substr
eden('string')->substr(int $start[, int $length]);
eden('string')->set('Hello')->substr(2, 2);
====
Same as PHP: substr_compare
eden('string')->substrCompare(string $needle, int $index);
eden('string')->set('Hello')->substrCompare('el', 3);
====
Same as PHP: substr_count
eden('string')->substrCount(string $needle);
eden('string')->set('Hello')->substrCount('l');
====
Same as PHP: substr_replace
eden('string')->substrReplace(string $replacement, int $start, int $length);
eden('string')->set('Hello')->substrReplace('yy', 2, 2);
====
Same as PHP: trim
eden('string')->trim();
eden('string')->set('Hello')->trim();
====
Same as PHP: ucfirst
eden('string')->ucfirst();
eden('string')->set('Hello')->ucfirst();
====
Same as PHP: ucwords
eden('string')->ucwords();
eden('string')->set('Hello')->ucwords();
====
Same as PHP: vsprintf
eden('string')->vsprintf(array $replacements);
eden('string')->set('Hello %s')->vsprintf(array('You'));
====
Same as PHP: wordwrap
eden('string')->wordwrap(int $length[, string $replacement]);
eden('string')->set('Hello You')->wordwrap(3, '<br />');
====
Contributions to Eden are following the Github work flow. Please read up before contributing.
##Setting up your machine with the Eden repository and your fork
- Fork the repository
- Fire up your local terminal create a new branch from the
v4
branch of your fork with a branch name describing what your changes are. Possible branch name types:- bugfix
- feature
- improvement
- Make your changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message")
##Making pull requests
- Please ensure to run
phpunit
before making a pull request. - Push your code to your remote forked version.
- Go back to your forked version on GitHub and submit a pull request.
- An Eden developer will review your code and merge it in when it has been classified as suitable.