How do I make php read and edit php source files?

Discussion in 'PHP' started by wwwbryan, Sep 26, 2009.

  1. #1
    I know you can use fopen and stuff. But I am making a php file to edit another php file that would be a config file. Such as

    $logo = 'img url';

    have php read and edit img url to lets say a real image url?

    How would I go about doing this?
     
    wwwbryan, Sep 26, 2009 IP
  2. aquilax

    aquilax Member

    Messages:
    126
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    33
    #2
    aquilax, Sep 26, 2009 IP
  3. ThomasTwen

    ThomasTwen Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Using fopen and stuff, you can read in the line and then run an str_replace() on it. That should do it
     
    ThomasTwen, Sep 26, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you could use something like this (untested):

    
    $source = file_get_contents('source.php');
    $source = preg_replace('\$logo = \'[^\']*\';', '$logo = \'new url\';', $source);
    file_put_contents('source.php', $source);
    
    PHP:
     
    premiumscripts, Sep 27, 2009 IP