eval()... now I feel _stupid_

From: Date: Wed, 19 Apr 2000 15:42:49 +0000
Subject: eval()... now I feel _stupid_
Groups: php.version4 
Request: Send a blank email to php-version4+get-13746@lists.php.net to get a copy of this message
I wrote a function that fgets a portion of a file. So far so good. Now I want PHP expand any variables contained in the returned portion. Whatever I tried, eval() doesn't work. I _know_ it's been here recently, I've read that topic, and I must say I didn't get it. Maybe I've missed something important, so if someone can give me an idiot proof explanation... function get_string( $filename , $separator , $position ) { global $php_errormsg ; unset( $php_errormsg ) ; $fp = fopen( $filename, 'r' ) ; if ( isset( $php_errormsg ) ) { return ; } ; while ( ! feof( $fp ) && $inc <= $position ) { $buffer = fgets( $fp, 4096 ) ; if ( ',,' . $separator == trim( $buffer ) ) { $inc++ ; } else { if ( $inc == $position && ',,' != substr( $buffer , 0 , 2 ) ) { $output .= $buffer ; } ; } ; } ; return $output ; } ; The structure of the fopen()ed file is this: ,,AAA aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb ,,BBB ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ddd ddd ddd ddd ddd ddd ddd ddd ddd ddd ddd ddd ,,BBB ,,AAA eee eee eee eee eee eee eee eee eee eee eee eee So, when I call get_string( 'file.txt' , 'BBB' , 1 ) it returns ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ddd ddd ddd ddd ddd ddd ddd ddd ddd ddd ddd ddd When I call get_string( 'file.txt' , 'AAA' , 1 ) it returns aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ccc ddd ddd ddd ddd ddd ddd ddd ddd ddd ddd ddd ddd That works fine. Now, I want to use variables in the file, but various attempts with/out eval() and/or PHP tags either report parse error, or just spit out the name of the variable in the HTML source. ____________________________________________________________ Cynic: A member of a group of ancient Greek philosophers who taught that virtue constitutes happiness and that self control is the essential part of virtue. cynic@mail.cz ICQ: 2808 2505

« previous php.version4 (#13746) next »