How to change filename with variable [closed]

0

This is the file with the variable I want.

# pt/lang.php
<?PHP
$rp_lang = "pt";
?>

This is the file that I want to insert but I want the variable to change the end to either "en" or "en" or any other.

# inc/saudacao_pt.php
<?PHP
$rp_saudacao = "Olá bom dia";
?>

This is the file that is made public.

# pt/index.php
<?php
include_once '../pt/lang.php';

include_once '../inc/saudacao_".$rp_lang.".php';
?>

Replacing ".$rp_lang." with "pt" works perfectly.

    
asked by anonymous 07.04.2015 / 15:57

2 answers

2

The problem is in concatenation. You are not closing the single quotes to concatenate the variable and the double quotes are unnecessary.

Do this:

include_once '../inc/saudacao_' . $rp_lang . '.php';
    
07.04.2015 / 16:16
3

I decided to respond because I had resolved on the comment. You mixed the apostrophe with quotation marks. The correct one:

include_once '../inc/saudacao_' . $rp_lang . '.php';

or

include_once "../inc/saudacao_$rp_lang.php";

See in the ideone .

    
07.04.2015 / 16:44