php - Change file content using RegEx -


im trying change file content nothing happening. there 1 word in .csv file - moonwalk. help, please?

$fn = file_get_contents("test.csv"); $pattern = '!moon!iu'; $replacement = 'lol'; preg_replace($pattern, $replacement, $fn); file_put_contents('fixed.csv', $fn); chmod("fixed.csv", 0664); 

the preg_replace function doesn't work in-place:

return values
preg_replace() returns array if subject parameter array, or string otherwise.
if matches found, new subject returned, otherwise subject returned unchanged or null if error occurred.

the result of replace returned, if need value should take if result of function:

$fn = preg_replace($pattern, $replacement, $fn); 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -