|
|
Joined: Dec 1999
Posts: 30,867
Master Elite Member
|
Make A WhiteSpace Delimited List into An ArrayYou want to allow a user to specify a list of items in a string. Each item can be delimited by any whitespace (space, tab, newline, or carriage return). In your code, you want to convert the list into an array so you can easily iterate it. This would be useful in the configuration section of a script where you want the user of the script to be able to specify a list of IP addresses, for example. // Translate all whitespace into spaces so they will be considered valid delimiters.
$MyList = strtr(MyList, array("\t"=>' ', "\n"=>' ', "\r"=>' '));
// Convert the literal IP list into an array.
$MyList = explode(' ', $MyList);
// Remove any empty array elements.
$Keys = array_keys($MyList, '');
foreach ($Keys as $Key) unset($MyList[$Key]);
|
|
|
|
|