Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda