Alright, perhaps it's my own feeble understanding of the str_replace function but I figured this should work:

$fp = "files\\10000\\" . $naturalcode . ".txt";
$file_array = file($fp);
echo ("<center><font class=size2>$naturalcode</font>
<hr width=70>
</center>
<br>
<font class=size4>");
for ( $i = 0; $i < count($file_array); $i++ ) {
		str_replace("?", " ", $file_array[$i]);
		echo $file_array[$i];
		echo "<br>";

}

As you can plainly see, it's opening a file and then displaying it in the browser. However, in all the txt documents, there is one instance of a question mark that I need replaced with just white space.

I thought str_replace("?", " ", $file_array[$i]); would do the trick but apparently not.

Any help is appreciated.

    str_replace is a function that return the modified string, so you may use a temp var, see below it may work

    for ( $i = 0; $i < count($file_array); $i++ ) {
            $ch = str_replace("?", " ", $file_array[$i]);
            echo $ch;
            echo "<br>";
    

      The above post is correct, but you may also need to use at least a '& nbsp ;' char to replace ?, as some versions of PHP dont support blank strings replacing with str_replace().

        Write a Reply...