View Single Post
  #2 (permalink)  
Old 08-20-06, 08:28 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:



function get_value_of($name)
{
     
$lines file('yourfile.txt');

     foreach (
array_values($lines) AS $line)
     {
          list(
$key$val) = explode('='trim($line) );
          
          if (
trim($key) == $name)
          {
                return 
$val;
          }
     }
     return 
false;

Untested bu should do it. Usage example:
PHP Code:



echo get_value_of('xyz'); 

EDIT:

This should also do it.
PHP Code:

function get_value_of($name)

{
    
$file 'data.txt';

    
preg_match('/'$name .'\s?=\s?([a-z0-9\s_-]*)\r?\n/i'file_get_contents($file), $matches);    
    return 
$matches[1];


Last edited by nico_swd; 08-20-06 at 11:10 AM. Reason: Forgot a semicolon.
Reply With Quote