Jump to content

Use Php To Modify A File


rick001

Recommended Posts

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

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));

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.