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

URL Checker...

This function check if an url is valid or not. function is_valid_url($url) { return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); }...

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', '...

alphaID - Translates a number to a short alhanumeric version...

Translates a number to a short alhanumeric version. e.g.: 9007199254740989 --> PpQXn7COf In most cases this is better than totally random ID generators because this can easily avoid duplicate ID's. Fo...

File size calculator...

File size calculator function return file size format into kb, mb or gb. function file_size($size, $out = 'kb', $precision = 2) { switch ($out) { case 'kb': return round($...