====, (*1)
, (*2)
Install
composer install eden/string
, (*3)
====, (*4)
Enable Eden
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., (*5)
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., (*6)
Eden::DECORATOR;
For example:, (*7)
Eden::DECORATOR;
eden()->inspect('Hello World');
====, (*8)
, (*9)
Introduction
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., (*10)
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., (*11)
echo eden('string')->set('hello')->substr(1, 3)->toupper()->replace('L', 'y'); //--> Eyy
Expressed vertically as below shows something more pleasing to a developer., (*12)
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., (*13)
====, (*14)
, (*15)
API
====, (*16)
, (*17)
addslashes
Same as PHP: addslashes, (*18)
Usage
eden('string')->addslashes();
Example
eden('string')->set('Hel"\'lo')->addslashes();
====, (*19)
, (*20)
bin2hex
Same as PHP: bin2hex, (*21)
Usage
eden('string')->bin2hex();
Example
eden('string')->set('01010100100')->bin2hex();
====, (*22)
, (*23)
chunkSplit
Same as PHP: chunk_split, (*24)
Usage
eden('string')->chunkSplit(int $length, string $separator);
Example
eden('string')->set('Hello')->chunkSplit(2, ':');
====, (*25)
, (*26)
convertUudecode
Same as PHP: convert_uudecode, (*27)
Usage
eden('string')->convertUudecode();
Example
eden('string')->set('%2&5L;&\`\n`\n')->convertUudecode();
====, (*28)
, (*29)
convertUuencode
Same as PHP: convert_uuencode, (*30)
Usage
eden('string')->convertUuencode();
Example
eden('string')->set('Hello')->convertUuencode();
====, (*31)
, (*32)
countChars
Same as PHP: count_chars, (*33)
Usage
eden('string')->countChars(int $min_length);
Example
eden('string')->set('Hello')->countChars(1);
====, (*34)
, (*35)
crypt
Same as PHP: crypt, (*36)
Usage
eden('string')->crypt(string $salt);
Example
eden('string')->set('Hello')->crypt('123');
====, (*37)
, (*38)
explode
Same as PHP: explode, (*39)
Usage
eden('string')->explode(string $separator[,int $limit]);
Example
eden('string')->set('1-2-3-4')->explode('-');
====, (*40)
, (*41)
hex2bin
Same as PHP: hex2bin, (*42)
Usage
eden('string')->hex2bin();
Example
eden('string')->set('3031303130313030313030')->hex2bin();
====, (*43)
, (*44)
htmlEntityDecode
Same as PHP: html_entity_decode, (*45)
Usage
eden('string')->htmlEntityDecode();
Example
eden('string')->set('&')->htmlEntityDecode();
====, (*46)
, (*47)
htmlentities
Same as PHP: htmlentities, (*48)
Usage
eden('string')->htmlentities();
Example
eden('string')->set('&')->htmlentities();
====, (*49)
, (*50)
htmlspecialchars
Same as PHP: htmlspecialchars, (*51)
Usage
eden('string')->htmlspecialchars();
Example
eden('string')->set('&')->htmlspecialchars();
====, (*52)
, (*53)
htmlspecialcharsDecode
Same as PHP: htmlspecialchars_decode, (*54)
Usage
eden('string')->htmlspecialcharsDecode();
Example
eden('string')->set('&')->htmlspecialcharsDecode();
====, (*55)
, (*56)
lcfirst
Same as PHP: lcfirst, (*57)
Usage
eden('string')->lcfirst();
Example
eden('string')->set('Hello')->lcfirst();
====, (*58)
, (*59)
ltrim
Same as PHP: ltrim, (*60)
Usage
eden('string')->ltrim();
Example
eden('string')->set(' Hello')->ltrim();
====, (*61)
, (*62)
md5
Same as PHP: md5, (*63)
Usage
eden('string')->md5();
Example
eden('string')->set('Hello')->md5();
====, (*64)
, (*65)
nl2br
Same as PHP: nl2br, (*66)
Usage
eden('string')->nl2br();
Example
eden('string')->set("Hel\nlo")->nl2br();
====, (*67)
, (*68)
pregReplace
Same as PHP: preg_replace, (*69)
Usage
eden('string')->pregReplace(string $regex, string $replacement);
Example
eden('string')->set('Hello')->pregReplace('/e/', 'i');
====, (*70)
, (*71)
quotedPrintableDecode
Same as PHP: quoted_printable_decode, (*72)
Usage
eden('string')->quotedPrintableDecode();
Example
eden('string')->set('Hello')->quotedPrintableDecode();
====, (*73)
, (*74)
quotedPrintableEncode
Same as PHP: quoted_printable_encode, (*75)
Usage
eden('string')->quotedPrintableEncode();
Example
eden('string')->set('Hello')->quotedPrintableEncode();
====, (*76)
, (*77)
Same as PHP: quotemeta, (*78)
Usage
eden('string')->quotemeta();
Example
eden('string')->set('Hello')->quotemeta();
====, (*79)
, (*80)
rtrim
Same as PHP: rtrim, (*81)
Usage
eden('string')->rtrim();
Example
eden('string')->set('Hello ')->rtrim();
====, (*82)
, (*83)
sha1
Same as PHP: sha1, (*84)
Usage
eden('string')->sha1();
Example
eden('string')->set('Hello')->sha1();
====, (*85)
, (*86)
sprintf
Same as PHP: sprintf, (*87)
Usage
eden('string')->sprintf([mixed $variable[, mixed $variable2 ..]]);
Example
eden('string')->set('Hello %s')->sprintf('You');
====, (*88)
, (*89)
ireplace
Same as PHP: str_ireplace, (*90)
Usage
eden('string')->ireplace(string $needle, string $replacement);
Example
eden('string')->set('Hello')->ireplace('l', 'y');
====, (*91)
, (*92)
pad
Same as PHP: str_pad, (*93)
Usage
eden('string')->pad(int $length, string $replacement);
Example
eden('string')->set('Hello')->pad(7, 'o');
====, (*94)
, (*95)
repeat
Same as PHP: str_repeat, (*96)
Usage
eden('string')->repeat(int $multiplier);
Example
eden('string')->set('Hello')->repeat(3);
====, (*97)
, (*98)
replace
Same as PHP: str_replace, (*99)
Usage
eden('string')->replace(string $needle, string $replacement);
Example
eden('string')->set('Hello')->replace('l', 'y');
====, (*100)
, (*101)
rot13
Same as PHP: str_rot13, (*102)
Usage
eden('string')->rot13();
Example
eden('string')->set('Hello')->rot13();
====, (*103)
, (*104)
shuffle
Same as PHP: str_shuffle, (*105)
Usage
eden('string')->shuffle();
Example
eden('string')->set('Hello')->shuffle();
====, (*106)
, (*107)
Same as PHP: strip_tags, (*108)
Usage
eden('string')->stripTags([string $allowableTags]);
Example
eden('string')->set('H<b>e</b>llo')->stripTags();
====, (*109)
, (*110)
stripcslashes
Same as PHP: stripcslashes, (*111)
Usage
eden('string')->stripcslashes();
Example
eden('string')->set('Hello')->stripcslashes();
====, (*112)
, (*113)
stripslashes
Same as PHP: stripslashes, (*114)
Usage
eden('string')->stripslashes();
Example
eden('string')->set('He\\llo')->stripslashes();
====, (*115)
, (*116)
istr
Same as PHP: stristr, (*117)
Usage
eden('string')->istr(string $needle);
Example
eden('string')->set('Hello')->istr('e');
====, (*118)
, (*119)
len
Same as PHP: strlen, (*120)
Usage
eden('string')->len();
Example
eden('string')->set('Hello')->len();
====, (*121)
, (*122)
pbrk
Same as PHP: strpbrk, (*123)
Usage
eden('string')->pbrk(string $needle);
Example
eden('string')->set('Hello')->pbrk('abcdefgh');
====, (*124)
, (*125)
pos
Same as PHP: strpos, (*126)
Usage
eden('string')->pos(string $needle);
Example
eden('string')->set('Hello')->pos('e');
====, (*127)
, (*128)
rev
Same as PHP: strrev, (*129)
Usage
eden('string')->rev();
Example
eden('string')->set('Hello')->rev();
====, (*130)
, (*131)
str
Same as PHP: strstr, (*132)
Usage
eden('string')->str(string $needle);
Example
eden('string')->set('Hello')->str('e');
====, (*133)
, (*134)
tok
Same as PHP: strtok, (*135)
Usage
eden('string')->tok(string $needle);
Example
eden('string')->set('Hello')->tok('e');
====, (*136)
, (*137)
tolower
Same as PHP: strtolower, (*138)
Usage
eden('string')->tolower();
Example
eden('string')->set('Hello')->tolower();
====, (*139)
, (*140)
toupper
Same as PHP: strtoupper, (*141)
Usage
eden('string')->toupper();
Example
eden('string')->set('Hello')->toupper();
====, (*142)
, (*143)
tr
Same as PHP: strtr, (*144)
Usage
eden('string')->tr(string $needle, string $replacement);
Example
eden('string')->set('Hello')->tr('e', 'y');
====, (*145)
, (*146)
substr
Same as PHP: substr, (*147)
Usage
eden('string')->substr(int $start[, int $length]);
Example
eden('string')->set('Hello')->substr(2, 2);
====, (*148)
, (*149)
substrCompare
Same as PHP: substr_compare, (*150)
Usage
eden('string')->substrCompare(string $needle, int $index);
Example
eden('string')->set('Hello')->substrCompare('el', 3);
====, (*151)
, (*152)
substrCount
Same as PHP: substr_count, (*153)
Usage
eden('string')->substrCount(string $needle);
Example
eden('string')->set('Hello')->substrCount('l');
====, (*154)
, (*155)
substrReplace
Same as PHP: substr_replace, (*156)
Usage
eden('string')->substrReplace(string $replacement, int $start, int $length);
Example
eden('string')->set('Hello')->substrReplace('yy', 2, 2);
====, (*157)
, (*158)
trim
Same as PHP: trim, (*159)
Usage
eden('string')->trim();
Example
eden('string')->set('Hello')->trim();
====, (*160)
, (*161)
ucfirst
Same as PHP: ucfirst, (*162)
Usage
eden('string')->ucfirst();
Example
eden('string')->set('Hello')->ucfirst();
====, (*163)
, (*164)
ucwords
Same as PHP: ucwords, (*165)
Usage
eden('string')->ucwords();
Example
eden('string')->set('Hello')->ucwords();
====, (*166)
, (*167)
vsprintf
Same as PHP: vsprintf, (*168)
Usage
eden('string')->vsprintf(array $replacements);
Example
eden('string')->set('Hello %s')->vsprintf(array('You'));
====, (*169)
, (*170)
wordwrap
Same as PHP: wordwrap, (*171)
Usage
eden('string')->wordwrap(int $length[, string $replacement]);
Example
eden('string')->set('Hello You')->wordwrap(3, '<br />');
====, (*172)
, (*173)
Contributing to Eden
Contributions to Eden are following the Github work flow. Please read up before contributing., (*174)
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.