Reputation: 4434
I have this code and it does not update the file. What am I doing wrong here?
$html = file_get_contents('/srv/www/htdocs/code.html');
$lastmon = Date("m", strtotime("first day of previous month"));
$html_r = str_replace('<strong>CODE_'.$lastmon.'</strong>', '<strong>CODE_'.Date("m").'</strong>', $html);
file_put_contents('/srv/www/htdocs/code.html', $html_r);
Upvotes: 0
Views: 222
Reputation: 4434
Actually, I found another way to set the code correctly in the template vs. changing the HTML. I will use PHP in the template to retrieve it from the database vs. having to change it on the fly.
Upvotes: 0
Reputation: 5806
$html = file_get_contents('/srv/www/htdocs/code.html');
$lastmon = date("m", strtotime("first day of previous month"));
$html_r = str_replace('<strong>CODE_'.$lastmon.'</strong>', '<strong>CODE_'.date("m").'</strong>', $html);
file_put_contents('/srv/www/htdocs/code.html', $html_r);
There's a function date() (and a class DateTime) and maybe you don't know that php is case sensitive.
Be sure that:
Upvotes: 2