View Full Version : Help With Regular Expressions

11-11-2003, 04:48 AM
I'm having trouble working with regular expresions.

What I want to do is grab a line of text from a string. The string is taken from a text file with line breaks... something like this:

$data="//blah blah
//blah blah"
Now, the variable $row_id="VALUE_ONE=" is specified by the user, what I want to do is grab the value after the coresponding line from the $data string. In this case, me desired result is 0.00001

Can someone help me out here, I only know the very basics of regular expressions but I presume I could use ereg_replace() to remove all the text before $row_id and all the text after the $row_id line... or something...

Thanks for your help.

11-14-2003, 11:46 AM
I would not regex unless I had to... (good job as well cos I hate it)

$key = 'VALUE_ONE' ;
$yaks = file( 'data.txt' ) ;
foreach( $yaks as $line ){
$bits = explode( '=' , $line ) ;
if( trim( $bits[0] ) == $key ){
$value = $bits[1] ;
break ;

echo $value;

11-16-2003, 12:38 PM
just out of interest, why is it you're so against regexp? i use them all the time, possibly too much actually, but i've never had any problems with it.