eden / string
Autoloading, error and exception handler
Installs: 389 506
Dependents: 19
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.1
- eden/core: 4.*
README
- 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
====
Install
composer install eden/string
====
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.
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');
====
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.
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.
====
API
====
addslashes
Same as PHP: addslashes
Usage
eden('string')->addslashes();
Example
eden('string')->set('Hel"\'lo')->addslashes();
====
bin2hex
Same as PHP: bin2hex
Usage
eden('string')->bin2hex();
Example
eden('string')->set('01010100100')->bin2hex();
====
chunkSplit
Same as PHP: chunk_split
Usage
eden('string')->chunkSplit(int $length, string $separator);
Example
eden('string')->set('Hello')->chunkSplit(2, ':');
====
convertUudecode
Same as PHP: convert_uudecode
Usage
eden('string')->convertUudecode();
Example
eden('string')->set('%2&5L;&\`\n`\n')->convertUudecode();
====
convertUuencode
Same as PHP: convert_uuencode
Usage
eden('string')->convertUuencode();
Example
eden('string')->set('Hello')->convertUuencode();
====
countChars
Same as PHP: count_chars
Usage
eden('string')->countChars(int $min_length);
Example
eden('string')->set('Hello')->countChars(1);
====
crypt
Same as PHP: crypt
Usage
eden('string')->crypt(string $salt);
Example
eden('string')->set('Hello')->crypt('123');
====
explode
Same as PHP: explode
Usage
eden('string')->explode(string $separator[,int $limit]);
Example
eden('string')->set('1-2-3-4')->explode('-');
====
hex2bin
Same as PHP: hex2bin
Usage
eden('string')->hex2bin();
Example
eden('string')->set('3031303130313030313030')->hex2bin();
====
htmlEntityDecode
Same as PHP: html_entity_decode
Usage
eden('string')->htmlEntityDecode();
Example
eden('string')->set('&')->htmlEntityDecode();
====
htmlentities
Same as PHP: htmlentities
Usage
eden('string')->htmlentities();
Example
eden('string')->set('&')->htmlentities();
====
htmlspecialchars
Same as PHP: htmlspecialchars
Usage
eden('string')->htmlspecialchars();
Example
eden('string')->set('&')->htmlspecialchars();
====
htmlspecialcharsDecode
Same as PHP: htmlspecialchars_decode
Usage
eden('string')->htmlspecialcharsDecode();
Example
eden('string')->set('&')->htmlspecialcharsDecode();
====
lcfirst
Same as PHP: lcfirst
Usage
eden('string')->lcfirst();
Example
eden('string')->set('Hello')->lcfirst();
====
ltrim
Same as PHP: ltrim
Usage
eden('string')->ltrim();
Example
eden('string')->set(' Hello')->ltrim();
====
md5
Same as PHP: md5
Usage
eden('string')->md5();
Example
eden('string')->set('Hello')->md5();
====
nl2br
Same as PHP: nl2br
Usage
eden('string')->nl2br();
Example
eden('string')->set("Hel\nlo")->nl2br();
====
pregReplace
Same as PHP: preg_replace
Usage
eden('string')->pregReplace(string $regex, string $replacement);
Example
eden('string')->set('Hello')->pregReplace('/e/', 'i');
====
quotedPrintableDecode
Same as PHP: quoted_printable_decode
Usage
eden('string')->quotedPrintableDecode();
Example
eden('string')->set('Hello')->quotedPrintableDecode();
====
quotedPrintableEncode
Same as PHP: quoted_printable_encode
Usage
eden('string')->quotedPrintableEncode();
Example
eden('string')->set('Hello')->quotedPrintableEncode();
====
quotemeta
Same as PHP: quotemeta
Usage
eden('string')->quotemeta();
Example
eden('string')->set('Hello')->quotemeta();
====
rtrim
Same as PHP: rtrim
Usage
eden('string')->rtrim();
Example
eden('string')->set('Hello ')->rtrim();
====
sha1
Same as PHP: sha1
Usage
eden('string')->sha1();
Example
eden('string')->set('Hello')->sha1();
====
sprintf
Same as PHP: sprintf
Usage
eden('string')->sprintf([mixed $variable[, mixed $variable2 ..]]);
Example
eden('string')->set('Hello %s')->sprintf('You');
====
ireplace
Same as PHP: str_ireplace
Usage
eden('string')->ireplace(string $needle, string $replacement);
Example
eden('string')->set('Hello')->ireplace('l', 'y');
====
pad
Same as PHP: str_pad
Usage
eden('string')->pad(int $length, string $replacement);
Example
eden('string')->set('Hello')->pad(7, 'o');
====
repeat
Same as PHP: str_repeat
Usage
eden('string')->repeat(int $multiplier);
Example
eden('string')->set('Hello')->repeat(3);
====
replace
Same as PHP: str_replace
Usage
eden('string')->replace(string $needle, string $replacement);
Example
eden('string')->set('Hello')->replace('l', 'y');
====
rot13
Same as PHP: str_rot13
Usage
eden('string')->rot13();
Example
eden('string')->set('Hello')->rot13();
====
shuffle
Same as PHP: str_shuffle
Usage
eden('string')->shuffle();
Example
eden('string')->set('Hello')->shuffle();
====
stripTags
Same as PHP: strip_tags
Usage
eden('string')->stripTags([string $allowableTags]);
Example
eden('string')->set('H<b>e</b>llo')->stripTags();
====
stripcslashes
Same as PHP: stripcslashes
Usage
eden('string')->stripcslashes();
Example
eden('string')->set('Hello')->stripcslashes();
====
stripslashes
Same as PHP: stripslashes
Usage
eden('string')->stripslashes();
Example
eden('string')->set('He\\llo')->stripslashes();
====
istr
Same as PHP: stristr
Usage
eden('string')->istr(string $needle);
Example
eden('string')->set('Hello')->istr('e');
====
len
Same as PHP: strlen
Usage
eden('string')->len();
Example
eden('string')->set('Hello')->len();
====
pbrk
Same as PHP: strpbrk
Usage
eden('string')->pbrk(string $needle);
Example
eden('string')->set('Hello')->pbrk('abcdefgh');
====
pos
Same as PHP: strpos
Usage
eden('string')->pos(string $needle);
Example
eden('string')->set('Hello')->pos('e');
====
rev
Same as PHP: strrev
Usage
eden('string')->rev();
Example
eden('string')->set('Hello')->rev();
====
str
Same as PHP: strstr
Usage
eden('string')->str(string $needle);
Example
eden('string')->set('Hello')->str('e');
====
tok
Same as PHP: strtok
Usage
eden('string')->tok(string $needle);
Example
eden('string')->set('Hello')->tok('e');
====
tolower
Same as PHP: strtolower
Usage
eden('string')->tolower();
Example
eden('string')->set('Hello')->tolower();
====
toupper
Same as PHP: strtoupper
Usage
eden('string')->toupper();
Example
eden('string')->set('Hello')->toupper();
====
tr
Same as PHP: strtr
Usage
eden('string')->tr(string $needle, string $replacement);
Example
eden('string')->set('Hello')->tr('e', 'y');
====
substr
Same as PHP: substr
Usage
eden('string')->substr(int $start[, int $length]);
Example
eden('string')->set('Hello')->substr(2, 2);
====
substrCompare
Same as PHP: substr_compare
Usage
eden('string')->substrCompare(string $needle, int $index);
Example
eden('string')->set('Hello')->substrCompare('el', 3);
====
substrCount
Same as PHP: substr_count
Usage
eden('string')->substrCount(string $needle);
Example
eden('string')->set('Hello')->substrCount('l');
====
substrReplace
Same as PHP: substr_replace
Usage
eden('string')->substrReplace(string $replacement, int $start, int $length);
Example
eden('string')->set('Hello')->substrReplace('yy', 2, 2);
====
trim
Same as PHP: trim
Usage
eden('string')->trim();
Example
eden('string')->set('Hello')->trim();
====
ucfirst
Same as PHP: ucfirst
Usage
eden('string')->ucfirst();
Example
eden('string')->set('Hello')->ucfirst();
====
ucwords
Same as PHP: ucwords
Usage
eden('string')->ucwords();
Example
eden('string')->set('Hello')->ucwords();
====
vsprintf
Same as PHP: vsprintf
Usage
eden('string')->vsprintf(array $replacements);
Example
eden('string')->set('Hello %s')->vsprintf(array('You'));
====
wordwrap
Same as PHP: wordwrap
Usage
eden('string')->wordwrap(int $length[, string $replacement]);
Example
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.