Hmm... the code you printed doesn't actually do a whole lot.
Your str_replace is in a function but you don't actually call that function, and that function actullay wouldn't work if you did call it.
function replaceText($text) {
$text = str_replace(" ", ";", $text);
}
This function has an private variable (not visible outside the function itself) called $text. If you call this function, passing in a variable as a parameter, it will store a copy of the value of that variable in its private $text variable. Then it will do the str_replace on it. But after that the function finishes, the private variable is destroyed, and the modified value is lost.
Try this:
function replaceText($text) {
$text = str_replace(" ", ";", $text); //Note four spaces between the first set of quotes
return $text;
}
$filename = 'tidlist.txt';
$text = file_get_contents($filename);
$open = fopen($filename, 'w');
fwrite($open, replaceText($text));
fclose($open);
Watch out for permissions though. Your web server is likely to be an unpriviliged user and so the directory you store the file in will need to be writeable by anyone. This presents its own problems.