php - How to: overwrite defined array with new POSTED data -
i'll redefine old unanswered & messy question 'cause i'm begging help. anyone...
i have line inside file (choices.php) has:
some choice1...||other choice2...||some data here...||overwrite me! old!
on other page there button post (and store/save) new data choices.php. newdata have overwrite text ($arrkey[3])
i tried explode
/ implode
, file_put_contents
, i've found browsing answers. far newdata being added @ end of line:
some choice1...||other choice2...||some data here...||overwrite me! old!i'm new data!
instead of:
some choice1...||other choice2...||some data here...||i'm new data!
if got question right, following code want :
$entries = explode('||', file_get_contents('choices.php')); $entries[3] = $_post['myfield']; // may want more strict checking before that. file_put_contents('choices.php', implode('||', $entries));
and, way, choices.php bad name, since file doesn't contain php code. it's won't prevent script working.
Comments
Post a Comment