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

angular - DownloadURL return null in below code -

python 2.7 - Given three nested dictionaries, sort the top two nested dictionaries from a value in the innermost dictionary? -