1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

what does this code do? (preg_replace)

Discussion in 'PHP & Perl' started by Mutikasa, Jan 23, 2013.

  1. Mutikasa

    Mutikasa Power Member

    Joined:
    May 23, 2011
    Messages:
    558
    Likes Received:
    212
    This code is from like dislike counter plugin for wordpress. I wanna know what does it do exactly
    Code:
    $changedDir='';
    if (!$changedDir)$changedDir = preg_replace('|wp-content.*$|','',__FILE__);
    thanks
     
  2. errabbaa

    errabbaa Registered Member

    Joined:
    Jun 11, 2012
    Messages:
    59
    Likes Received:
    9
    The first line and the if statement is useless there. $changedDir is empty and if statement would always turn to true since $changedDir is empty.
    PHP Code:
    $changedDir = preg_replace('|wp-content.*$|','',__FILE__);

    The above statement seems like its trying to get the root path / Wordpress directory where wp-contents folder is located (incase this is stored in a theme file or plugin). Its removing everything after and including wp-content in __FILE__ (which gives the current file path)
     
    • Thanks Thanks x 1
    Last edited: Jan 28, 2013