Bluehost.com Web Hosting $6.95

Parsing Variables

This is a discussion on Parsing Variables within the PHP General forums, part of the PHP Programming Forums category; I would like to create a script that reads a file name that follows a specific format and have it ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-31-2003
Jason Williard
 
Posts: n/a
Default Parsing Variables

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.

Any assistance would be appreciated.

Thanks,
Jason


Reply With Quote
  #2 (permalink)  
Old 07-31-2003
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] Parsing Variables

* Thus wrote Jason Williard (jason@jasondubya.com):
> 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."
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:58 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0