ב"ה
דוגמא א:
PHP קוד:
include($file);
$file_contents=file_get_contents($file);
$file_content=str_replace($INFO['sql_database'],$new_value,$file_contents);
$r=fopen($file,+w);
fwrite($r,$file_content);
עם דוגמא א' יכולה להיות בעיה עם הקובץ מכיל עוד מחרוזת כמו הערך של $INFO['sql_database']
אז כדי לפתור את זה אפשר לשלב את השם של המשתנה בהחלפה.
דוגמא ב':
PHP קוד:
<?php
include($file);
$file_contents=file_get_contents($file);
$file_content=str_replace('$INFO[\'sql_database\'] = \''.$INFO['sql_database'].'\';',$new_value,$file_contents);
$r=fopen($file,+w);
fwrite($r,$file_content);
?>
אני לפעמים משתמש בצורה אחרת שהיא אולי יותר בזבזנית במשאבים אבל יותר נוחה לכותב(עצלנות...)