Jump to content

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

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.