Skip to content

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;

between

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 ']
*/

formatBytes

Format bytes number into more human readable text.

Str::formatBytes($bytes, $precision = 2);

# Example
echo Str::formatBytes(4096);

// Output: 4KB

random

Create random string from alphanumeric character.

Str::random($length = 6, $withSymbol = false);

# Example
echo Str::random();

// Output: j7d3uB

mimeType

Return mime type of file extension

Str::mimeType('exe');

// Output: application/octet-stream

utf8ize

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));
Clone this wiki locally