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

Change timestamp to custom format...

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

Download a file from web to local...

Use this function to download a file from web to local machine. function WgetFile( $URL, $dir ) { $nomefile = $dir . "/" . basename( $URL ); if ( copy( $URL, $nomefile ) ) { retu...

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

Detect leap year...

Detect leap year for gregorian and shamsi date. function gLeapYear($year) { if (($year % 4 == 0) and (($year % 100 != 0) or ($year % 400 == 0))) return true; else return ...