Hi PHP'ers,
I'm a little embarassed about this, but it appears I am unclear on the concept of str_replace. Hopefully you can set me straight.
I have a little test PHP file to take a form field input and use it to replace some text in a plain text file. But it keeps replacing the search string with blanks and, in local test mode, with funny little square boxes at the end of the file.
I've tried using ereg_replace instead, with the same result. Below is a copy of the PHP file code; very simple as you can see. You can try it yourself if you make a test text file that has a line like "Here is some Times Roman text."
<?php
if(!$_POST['B1']) {
echo ('<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test Input Form</title>
</head>
<body>
<form method="POST" action="'.$PHP_SELF.'">
<p><input type="text" name="FontName" Value="Enter Font" size="20"></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form></body></html>');
} ;
$hFile = fopen( "test1.txt", "r+" );
$orig_file = file_get_contents("test1.txt");
// Test file contains two lines, one says "Here is some Times Roman text."
$new_file = str_replace("Times Roman", $FontName, $orig_file);
fwrite($hFile, $new_file);
fclose( $hFile );
if( isset( $B1 ) ) {
echo 'File Written. Open Test1.txt in Notepad to see results. New Font Name is: ' ;
echo $FontName;
} ;
?>
Why won't this work?