mysql - how to get string in among of lines using php -
i having file settings.txt. contains lines like
set version=3 set backup_drive=d:\ set backup_directory=backup\ set hourly_directory=hourly\ set input_directory=c:\mysql\data\cdr\ set username=username set password=password
this file @ other location or on other server. have file using ...
$frserver = file_get_contents("http://ip here/cdr/settings.txt");
i used
$file = file_get_contents("http://ip heresettings.txt"); $filearr = explode("\r\n",$file); echo $filearr[5]; // output: set username=desired username
and "set username=desired username" bt want "desired username"..just issue left nw
now unable username , password it. how username , password can compare them in db...
assuming
$frserver = 'set version=3 set backup_drive=d:\ set backup_directory=backup\ set hourly_directory=hourly\ set input_directory=c:\mysql\data\cdr\ set username=username set password=password';
the whole solution these 2 lines:
preg_match_all('~^set\s+([^=]+)=(.*)$~m', $frserver, $matches); $params = array_combine($matches[1], $matches[2]);
so after can retrieve variables $params['username']
, $params['password']
correspondingly.
live example on ideone: http://ideone.com/pn2wbp
Comments
Post a Comment