Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Overwriting a string by concatenating another string

There are hundreds of places in my project which contain the following code:

include $root . $template;

Where $root is document root for the relevant part of the CRM and $template is the HTML template file. The $root variable is different for different parts of the CRM.

I want to now make all parts of the CRM use the same template file. I can't simply change $root to the central document root because there are other places in the code which use that variable. I just want to change it for loading the template.

Is there a way to save time, so I don't have to go over all the places in my code where this appears? Is there perhaps a way of making the $template string overwrite the $root string when concatinated?

i.e.

$root="$_SERVER['document_root']."\some_folder";
$template="[something_to_ignore_concatination?]".$_SERVER['document_root']."\template_file";
//So $root.$template = just $template
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Warning: What you'll see below is an abomination, do not use this in real software!

Assuming these values:

$_SERVER['document_root'] = 'path/to/root'

$root == $_SERVER['document_root'] . '/some_folder' == 'path/to/root/some_folder'

$template == '/' . $_SERVER['document_root'] . '/file.php' == '/path/to/root/file.php'

$root . $template == 'path/to/root/some_folder/path/to/root/file.php'

You could symlink

path/to/root/some_folder/path/to/root -> path/to/root/

So that the double path still gets resolved.

Note: The paths above should be treated as relative to one of the folders added to the PHP include_path.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!