Parse a string into separate words

Parse a string into separate words (array output).

function parser($str, $char = ' ')
{
    $str = trim($str);
    $str = $str . $char;
    $len = strlen($str);
    $words = array();
    $w = '';
    $c = 0;
    for ($i = 0; $i < $len; $i++)
        if ($str[$i] != $char)
            $w = $w . $str[$i];
        else
            if (($w != $char) and ($w != '')) {
                $words[$c] = $w;
                $c++;
                $w = '';
            }
    return $words;
}
 
$x = parser('hello world!');
print_r($x);

Tags

No tag here.

Recommended pages

Delete or Remove all files and folders in a directory‎...

If you want to delete everything from folder (including subfolders) use this function. function removeDir( $dir ) { if ( is_dir( $dir ) ) { $objects = scandir( $dir ); foreach ( $o...

Detect file extension function...

This function is used to find the file extension also you can use pathinfo() function for get information about a file path. function ext($file_name) { return substr($file_name, strrpos($fi...

Number Format...

Format a number with grouped thousands......

Human readable file size...

This function return formatting of file sizes in a human readable format. function formatFileSize( $size ) { $file_size = $size; $i = 0;   $name = array( 'byte', 'kB', 'MB', '...