-
-
Notifications
You must be signed in to change notification settings - Fork 1
Extend_Strings
StefansArya edited this page Apr 18, 2019
·
1 revision
This feature will help you when doing string any manipulation.
You may need to import this feature on top of your code.
use \Scarlets\Extend\Strings as Str;
Obtain text between text.
Str::between($start, $end, &$str, $all = false);
# Example
$string = 'hello my world, and hello your world';
echo(Str::between('hello', 'world', $string, true));
/* Output
[' my ', ' your ']
*/
Format bytes number into more human readable text.
Str::formatBytes($bytes, $precision = 2);
# Example
echo Str::formatBytes(4096);
// Output: 4KB
Create random string from alphanumeric character.
Str::random($length = 6, $withSymbol = false);
# Example
echo Str::random();
// Output: j7d3uB
Return mime type of file extension
Str::mimeType('exe');
// Output: application/octet-stream
Encode UTF8 text that can't be processed by json_encode
.
This $data
can be array, object, or string.
After using this function, the $data
will be changed
and will return the referece of $data
.
Str::utf8ize(&$data);
# Example
$data = ['Hôuse', 'Dôgs', 'Frôgs'];
echo json_encode(Str::utf8ize($data));