Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:30:35+00:00 2026-06-14T04:30:35+00:00

I have a script that is duplicating a file, but after I duplicate that

  • 0

I have a script that is duplicating a file, but after I duplicate that file, I need a script to dynamically change certain string values inside that file.

Through searching around I found that file_get_contents and str_replace work best for this, but for some reason the script I have does not work.

This is what I have:
(note: $wikiname is the name of the new wiki being created

$template = file_get_contents("/var/www/wiki/". $wikiname ."/LocalSettings.php");

$snReplace = str_replace("templatewiki", $wikiname, $template);
$mnReplace = str_replace("Templatewiki", $wikiname, $template);
$spReplace = str_replace("/iadmin/wikifresh", "/wiki/".$wikiname, $template);
$wgDBname = str_replace("template_wiki", $wikiname, $template);

Im searching for the exact string and trying to replace that string with the wiki name. But for some reason, this doesn’t work at all.

Is there an obvious issue I’m missing?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:30:37+00:00Added an answer on June 14, 2026 at 4:30 am

    str_replace returns the modified string, the one you pass as the argument remains unchanged. This is what you need to do:

    $template = file_get_contents("/var/www/wiki/" . $wikiname . "/LocalSettings.php");
    $template = str_replace("templatewiki", $wikiname, $template);
    $template = str_replace("Templatewiki", $wikiname, $template);
    $template = str_replace("/iadmin/wikifresh", "/wiki/" . $wikiname, $template);
    $template = str_replace("template_wiki", $wikiname, $template);
    

    You can also use strtr function to achieve same result:

    $template = strtr(file_get_contents("/var/www/wiki/" . $wikiname . "/LocalSettings.php"), array(
        "templatewiki"      => $wikiname,
        "Templatewiki"      => $wikiname,
        "/iadmin/wikifresh" => "/wiki/" . $wikiname,
        "template_wiki"     => $wikiname
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goodday, I have script,that loops all files in directory, but I need to hide
I have script that reads remote file content and writes it to local server.
I have a sh/bash script that needs to call a batch file with parameters
I have this script that run to fix my menu bar to the browser
I have a script that recursively loops through all the sub directories and compresses
I have a script that submits data via an ajax POST. It is called
I have following script that executes all the .reg files in the current directory.
I have a script that obtains information about the current folders and subfolders within
I have a script that resizes called resize Here is the script: <? echo
I have a script that uses a ton of redirects. About half way through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.