1. Go to this page and download the library: Download atk14/string4 library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$s = new String4("Hello World");
$s = new String4("Héllo", "UTF-8"); // explicit encoding
$s = new String4($anotherString4); // copy from another instance
$s = String4::ToObject("Hello");
$s = String4::ToObject($s); // returns a copy, safe to pass around
$s = String4::ToObject("Héllo", "ISO-8859-2");
(new String4("Héllo"))->length(); // 5
(new String4(""))->length(); // 0
(new String4("hello"))->upcase(); // "HELLO"
(new String4("héllo"))->upper(); // "HÉLLO"
(new String4("HÉLLO"))->lower(); // "héllo"
(new String4("HELLO"))->isUpper(); // true
(new String4("Hello"))->isUpper(); // false
(new String4(""))->isUpper(); // false
(new String4("hello"))->isLower(); // true
(new String4("Hello"))->isLower(); // false
(new String4("hello world"))->capitalize(); // "Hello world"
(new String4("Hello World"))->uncapitalize(); // "hello World"
(new String4("hello_world"))->camelize(); // "HelloWorld"
(new String4("hello_world"))->camelize(["lower" => true]); // "helloWorld"
(new String4("some_xml_parser"))->camelize(); // "SomeXmlParser"
(new String4("HelloWorld"))->underscore(); // "hello_world"
(new String4("BlogPost"))->underscore(); // "blog_post"
(new String4("x-men: the last stand"))->titleize(); // "X Men: The Last Stand"
(new String4("author_id"))->titleize(); // "Author"
(new String4("author_id"))->titleize(["keep_id_suffix" => true]); // "Author Id"
$s = new String4("Hello World");
$s->gsub('/[aeiou]/', '*');
// "H*ll* W*rld"
$s->gsub('/\b\w/', function($m) {
return strtoupper($m[0]);
});
// "Hello World" (capitalize first letter of each word)
(new String4("World"))->prepend("Hello "); // "Hello World"
(new String4("Hello"))->append(" World"); // "Hello World"
(new String4("Hello"))->first(); // "H"
(new String4("Hello"))->first(3); // "Hel"
(new String4("Hello"))->at(0); // "H"
(new String4("Hello"))->at(1); // "e"
(new String4("Hello"))->at(-1); // "o"
$s = new String4("Hello World, how are you?");
$s->truncate(14);
// "Hello World..."
$s->truncate(14, ["omission" => " →"]);
// "Hello World →"
$s->truncate(14, ["omission" => "", "separator" => " "]);
// "Hello World,"
(new String4("Hi!"))->chars();
// [String4("H"), String4("i"), String4("!")]
(new String4("Hi!"))->chars(["stringify" => true]);
// ["H", "i", "!"]
$s = new String4("one two three");
$s->split(" ");
// [String4("one"), String4("two"), String4("three")]
$s = new String4("one two three");
$s->pregSplit('/\s+/');
// [String4("one"), String4("two"), String4("three")]
$s = new String4(" Hello World ");
$s->trim(); // "Hello World"
$s->trim(true); // also removes zero-width spaces, BOM, etc.
(new String4(" Hello World "))->squish(); // "Hello World"
(new String4("<b>Hello</b> <i>World</i>"))->stripTags(); // "Hello World"
$html = "<h1>Welcome at our <em>web</em><small>site</small>!</h1>"
. "<p>We are here to help you.<br>Write us.</p>";
(new String4($html))->stripHtml();
// "Welcome at our website! We are here to help you. Write us."
(new String4("Héllo Wörld"))->toAscii();
// "Hello World"
(new String4("příliš žluťoučký kůň"))->toAscii();
// "prilis zlutoucky kun"
(new String4("apple"))->pluralize(); // "apples"
(new String4("Sad man"))->pluralize(); // "Sad men"
(new String4("apples"))->singularize(); // "apple"
(new String4("Happy people"))->singularize(); // "Happy person"
(new String4("Book"))->tableize(); // "books"
(new String4("BlogPost"))->tableize(); // "blog_posts"
(new String4("CookieConsent"))->tableize(); // "cookie_consents"
// Trim every line
$result = $s->eachLineMap(function($line) {
return $line->trim();
});
// Add a quote prefix to every line
$result = $s->eachLineMap(function($line) {
return $line->prepend("> ");
});
// Remove empty lines
$result = $s->eachLineFilter();
// Keep only lines that start with "#"
$result = $s->eachLineFilter(function($line) {
return $line->match('/^#/');
});
echo String4::RandomString(); // 32-character random string
echo String4::RandomString(16); // 16-character random string
echo String4::RandomString([
"length" => 20,
"extra_chars" => "#!&@",
]);
// e.g. "@vIxpVo!qD4A#n5Rb2E&"
echo String4::RandomNumericString(); // e.g. "482917"
echo String4::RandomNumericString(4); // e.g. "3071"
echo String4::RandomNumericString(8); // e.g. "52847391"
echo String4::RandomPassword(); // e.g. "68ynedeSA6"
echo String4::RandomPassword(12); // e.g. "68ynedeSA634"
echo String4::RandomPassword(10)->upper(); // e.g. "EVUH923244"
$s->fixEncoding();
// invalid bytes replaced with "▒"
$s->fixEncoding("?");
// invalid bytes replaced with "?"
$s->fixEncoding(["replacement" => "_"]);
// invalid bytes replaced with "_"
echo String4::ToObject(" Hello World! ")
->trim()
->lower()
->replace("!", "")
->toSlug();
// "hello-world"
echo String4::ToObject("CookieConsentsController")
->gsub('/Controller$/', '')
->singularize()
->underscore();
// "cookie_consent"
echo String4::ToObject(" lots of whitespace \n\n\n and newlines ")
->squish();
// "lots of whitespace and newlines"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.