|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-08-31 03:00 UTC] jim dot michaels at Jesusnjim dot com
Description:
------------
file_put_contents() does not overwrite if file exists. if file exists, file is not touched. if file is open in programmer's editor, rw.txt file does not refresh. this could be related with c++ old gcc bug in fstream's std::ios_base::creat notworking for while a number of years.
Test script:
---------------
<?php
$a=file_get_contents("\\w\\Jesusnjim\\menu7a.xml");
$a=preg_replace('/\//','\\',$a);
file_put_contents("\\w\\Jesusnjim\\rw.txt", $a);
?>
2nd time:
<?php
$a=file_get_contents("\\w\\Jesusnjim\\menu7a.xml");
$a=preg_replace('/\//','\\\\',$a);
file_put_contents("\\w\\Jesusnjim\\rw.txt", $a);
?>
Expected result:
----------------
expected / to be changed to \\ and for rw.txt to be changed in programmer's editor jedit and to be notified that file was changed.
Actual result:
--------------
if file is open in programmer's editor, rw.txt file does not refresh.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 23:00:01 2025 UTC |
Can't reproduce this issue on a Windows 8 with PHP 7.1 Beta 3 from windows.php.net QA I tried with a local path and with a SMB remote path: <?php error_reporting(E_ALL); file_put_contents('test.txt', "HOLA"); var_dump(file_get_contents('test.txt') == "HOLA"); file_put_contents('test.txt', "ADIOS"); var_dump(file_get_contents('test.txt') == "ADIOS"); file_put_contents('\\\\server\folder\test.txt', "HOLA"); var_dump(file_get_contents('\\\\server\folder\test.txt') == "HOLA"); file_put_contents('\\\\server\folder\test.txt', "ADIOS"); var_dump(file_get_contents('\\\\server\folder\test.txt') == "ADIOS"); D:\fms\php710beta3>php file.php bool(true) bool(true) bool(true) bool(true)<?php $a="a / b"; $a=preg_replace('/\//','\\',$a); echo file_put_contents("rw.txt", $a); $a=preg_replace('/\//','\\\\',$a); echo file_put_contents("rw.txt", $a); ?> outputs 55 and rw.txt contains a \ b which it should not. no it's not open in an editor. create always is not enabled in the interpreter. 2nd write fails to write to file, same as before. 5==strlen($a).am now using this code. <?php $a="a / b\r\n"; echo file_put_contents("rw.txt", $a); $a=preg_replace('/\//','\\\\', $a);//bug in PCRE doesn't replace / with 2 \ chars echo $a; echo file_put_contents("rw.txt", $a); system("dir rw.txt"); system("type rw.txt");//should be a \\ b ?> and this does overwrite like it's supposed to.> No bug. There is exactly one bug in this bug report and it is > with your own code. Not with PHP. Not with PCRE. That. Suggestion: use str_replace() instead of preg_replace() in this case: str_replace('/', '\\', $a);