Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow PHP eding another PHP file

    Hi. me and my friends are working on a text based rpg game. what i need is to have PHP to go and edit a file that contains a huge PHP file like below

    Example:
    PHP Code:
    <?php
    $color1 
    red;
    $color2 blue;
    $color3 green;
    ?>

    Pages like these are going to be included in other files to set variables. But as the player advances through the game these variables will change. I need a PHP to get this file, find a specific variable, such as $color2, and edit it.

    For example, if i have $money = 100; in that file and the player earns $10, I need PHP to find $money and add 10 to it.
    How can I do this.
    Also, the game is in early development and I will plan on using SQL. But not now...

    Thank You!
    $must = $_GET['life'];

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    You will save yourself a lot of coding if you do it in sql right now...

    If you insist on doing it this way, write a php library with basic functions like "set_color" and "get_color" so that when you shift this to mysql all you need to do is change the insides of those definitions - you don't have to change code in more than one file.

    As for what you're trying to do now, I'd suggest using fseek and fgets

    http://us2.php.net/manual/en/function.fgets.php
    http://us2.php.net/manual/en/function.fseek.php

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so if i use this code:
    Code:
    <?php
    
    $fp = fopen('somefile.txt', 'r');
    
    // read some data
    $data = fgets($fp, 4096);
    
    ?>
    how do i have the script select a spicific variable. then what would i do to have it edit it
    and what is the 4096 for?
    thanks
    $must = $_GET['life'];


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •