psStrToAry() Returns an array from a delimited string
Description:
Perfect when you want an array of items, can be passed as string Ignores empty items. Note: if you pass an array, it will return said array
Usage:
$str = psStrToAry($string,$delimiter);
Example:
$ary = psStrToAry("Red , ,Blue, "); // returns array("Red","Blue")
Code:
function psStrToAry($str, $d=",") { if (is_array($str) == true) { return $str; }
if ( substr_count($str,$d) < 1 ) { $r = trim($str); if ($r != "") { $res[] = $r; } } else { $ary = explode($d,$str); foreach ($ary as $item) { if (trim($item) != "") { $res[] = trim($item); } } } return $res; }
Changlelog:
|
|