RE: [PHP] $_POST not working with str_replace

From: Date: Wed, 24 Mar 2004 22:00:31 +0000
Subject: RE: [PHP] $_POST not working with str_replace
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-181398@lists.php.net to get a copy of this message
> Ok here's the deal, I cut out the middle man, went straight > to the script, assigned my variable a string, and loaded the > rtf page, NADA, ZIP, ZILCH!! At least as far as this test is concerned, I hope you have a nice soft desk to bang your head on. Check your assignment operator one more time. > <?php > //print_r($_POST); > //$na = $_GET['f']; > ---->$na == "Me"; If your script has the same "==" where a plain ol' "=" should be, that'd account for the replacement being empty (since it's replaced with $na, which wasn't assigned). As far as the original troubles you're trying to diagnose, I loosely replicated your setup and everything worked as expected. (I just made up a Lettertest.rtf file.) Below are the working files, see if they work for you: Cheers, Rick Form.html: ========================================= <HTML> <BODY> <FORM action="rtf1.php" method="POST"> <INPUT type="text" name="fname"> <INPUT type="submit" value="Test"> </FORM> </BODY> </HTML> ========================================= rtf1.php: ========================================= <?php $name = $_POST['fname']; $filename = "Lettertest.rtf"; header( 'Content-Type: application/msword' ); header('Content-Disposition: inline, "rtftest.rtf"'); $fp = fopen( $filename, "r" ); $output = fread( $fp, filesize( $filename ) ); $output = str_replace( '<<FNAME>>', $name, $output ); echo $output; ?> ========================================= Lettertest.rtf: ========================================= a line of test Hello, <<FNAME>> another line =========================================

« previous php.general (#181398) next »