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

How to created mixed arguments function...

This way useful for create mixed arguments function. function foo() { $args = func_get_args(); print_r($args); }   foo(1, 1256, 6, 17); //mixed ...   -------------------Out-...

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($...

Resize image function...

Resize image function for jpg format. $mood between max and min. if you choose max, this mean max size of image is $ta otherwise min size of image is $ta. function makeTheThumb( $ppath, $ta, $mood ) ...

Best way to get user ip address in php...

Here is a function to getting ip using filter of local and lan ip's. function get_ip() { $list = array( 'REMOTE_ADDR', 'CLIENT_IP', 'HTTP_CLIENT_IP', 'HTTP_PROXY_CONNECTION',...