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

Email Address Checker...

This function check if an e-mail address is valid or not. function valid_email($email) { return preg_match('/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/', $email);...

Random string generator...

Random string generator. Optionally, you can give it a desired string length. function rnd_string($len = 24) { $str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $str...

UTF8 string length counter...

The best way to determine the character count of a UTF8 string. function strlen_utf8( $str ) { return mb_strlen( $str, 'UTF-8' ); }   //or... function strlen_utf8( $str ) { $c = 0;...

Change timestamp to custom format...

Use this function for change timestamp to custom format......