Jump to content

separating words


nick5449

Recommended Posts

[code]
function strip_blanks($arr)
{
        foreach( $arr as $ki=>$val )
        {
                if(trim($val)=='')
                {unset($arr[$ki]);}
                else{$arr[$ki] = trim($val);}
        }return($arr);
}

//Replace String
$str = "Hello, this is a comma, separated, string with, comas!!";
$expl = explode(',',$str);
$stripped = strip_blanks($expl);
[/code]

Stripped will now contain:
[code]
Array
(
    [0] => Hello
    [1] => this is a comma
    [2] => separated
    [3] => string with
    [4] => comas!!
)
[/code]
Link to comment
https://forums.phpfreaks.com/topic/14335-separating-words/#findComment-56488
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.