rick001 Posted December 12, 2012 Share Posted December 12, 2012 Hi i am trying to write a script which will allow me to add new channels and moderators to the frug ajax chat. Here is what i need to do, // Sample moderator user: $users[2] = array(); $users[2]['userRole'] = AJAX_CHAT_MODERATOR; $users[2]['userName'] = 'moderator'; $users[2]['password'] = 'moderator'; $users[2]['channels'] = array(0,1); the script needs to be able to search user.php file for this set of code and then append it to add new users. My problem is i can use fseek() to point to the position after //Sample moderator user: but the new entries needs to be made after the $users[2]['userRole'] = AJAX_CHAT_MODERATOR; line and below the previous user already assigned. Also i need to modify the last line $users[2]['channels'] = array(0,1); and add more values into the array(0,1) . Any suggestions? Link to comment https://forums.phpfreaks.com/topic/271901-use-php-to-modify-a-file/ Share on other sites More sharing options...
trq Posted December 12, 2012 Share Posted December 12, 2012 I would pull everything you need to change out and into a separate file. Then include that file into the file it is currently in. Once it's in a separate file it will be very easy to manipulate as it's just an array. <?php include 'somefile.php'; // manipulate the $users array all you need. file_put_contents('somefile.php', "<?php\n" . var_export($users)); ?> Link to comment https://forums.phpfreaks.com/topic/271901-use-php-to-modify-a-file/#findComment-1398889 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.