[Tool/Web/Other] [PHP] help needed..
#7

okay, took a little longer then i thought it would, but thats alright.
there's probably a more efficent method to do this, but i suppose this will do for now

PHP код:
function set($data$key$value) {
    
$regex "/^$key+.+\n/";
    
$data preg_replace($regex"$key=$value\r\n"$data);
    return 
$data;    
}

function 
get($data$key) {
    
$data explode("\n"$data);
    
    
$regex "/$key+=+.+$/";
    
$f "";
    for(
$i 0$i count($data); $i++) {
        if(
preg_match($regex$data[$i])) {
            
$f $data[$i];
            break;
        }
    }
    
    if(
is_array($f))
        return 
false;
    else {
        
$regex "/$key+=/";
        
$f preg_replace($regex''$f); //comment this line if you would like it to return KEY=VALUE instead of just VALUE
        
return $f;
    }

let me give you a quick rundown of how it works.
set requires 3 inputs, the current data in your file, you have it defined as $data, it requires a key and a value ( like dini ). the key is what it searches for, the value is what it updates it with. When it's done it returns an updated version of the whole file, or whatever data was.

Heres an example on how to use it

PHP код:
if($data)
{
    
$data set($data"parameter1"22);
    
$data set($data"parameter3"62);
    
fwrite($handle$data);

get requires 2 values, data and the key. It will search for the key and return its corresponding VALUE, or false if it can't find it.

example
PHP код:
if($data
{
    echo 
get($data"parameter1");

hope it helps, and let me know if something doesnt work, i checked it a couple of times but im tired as shit today so i may have left an error out somewhere
Reply


Messages In This Thread
[PHP] help needed.. - by SiJ - 15.01.2010, 12:00
Re: [PHP] help needed.. - by Christopher. - 15.01.2010, 15:48
Re: [PHP] help needed.. - by SiJ - 15.01.2010, 16:16
Re: [PHP] help needed.. - by darkrider366 - 15.01.2010, 19:58
Re: [PHP] help needed.. - by iLinx - 15.01.2010, 20:02
Re: [PHP] help needed.. - by SiJ - 15.01.2010, 20:38
Re: [PHP] help needed.. - by iLinx - 15.01.2010, 21:53
Re: [PHP] help needed.. - by SiJ - 16.01.2010, 07:15
Re: [PHP] help needed.. - by mooman - 16.01.2010, 11:50
Re: [PHP] help needed.. - by iLinx - 16.01.2010, 13:35

Forum Jump:


Users browsing this thread: 1 Guest(s)