* Thus wrote Jason Williard ([EMAIL PROTECTED]):
> I would like to create a script that reads a file name that follows a
> specific format and have it parsed into 2 variables. The format is as
> follows:
>
> cli_info-ACCOUNT-USERNAME.dat
>
> The two variables that I would like to get out of this are the ACCOUNT and
> USERNAME. The rest of the information can be discarded. I can get the
> entire filename into a variable, but I am not sure how to parse it properly.
One method would be to use the preg_split():
list($extra, $account, $username) =
split('/[-.]/', 'cli_info-ACCOUNT-USERNAME.dat', 3);
or a a preg_match():
preg_match('/cli_info-([^-]+)-([^.]+)\.dat/', $str, $matches);
$account = $matches[1];
$username = $matches[2];
This is assumint that account wont contain a '-' and username wont
contain a '.'.
HTH,
Curt
--
"I used to think I was indecisive, but now I'm not so sure."
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php