0

Hi,
I've been recently trying to create a language change script. Everything goes smoooth but there are several complexed places inside the page that needs some advanced php code.
So the main problem is: I do not know how to make a variable from main page work in array.

    $eng = array(
        'cp_ver' => 'v1.0.1 ',
        'cp_title' => 'Control Panel ',
        'cp_sub' => 'Welcome to central controll center. ',
        'logout_btn' => 'Logout ',
        'no_profiles' => 'You do not have a profile yet. ',
        'profile_permission' => 'You belong to ' . $group . ' with a permission of ' . $permission .'',
    );

profile_permission property is like a real pain in the hole for me right now.
this code is located in a langs.php file which is included into main page index.php.
Please help me to sort this out.

Edited by Giedrius_1: issue in layout

3
Contributors
2
Replies
18
Views
3 Years
Discussion Span
Last Post by broj1
0

Hi, you can use sprintf for this task:

echo sprintf($eng['profile_permission'], $group, $permission);

However before doing this you need to change the variables in the array with the value types, in your case:

$eng['profile_permission'] = 'You belong to %s with a permission of %s';

Where %s stands for string, here the documentation:

Bye!

0

Maybe the simplest way would be to address the array element directly:

$eng['profile_permission'] = 'You belong to ' . $group . ' with a permission of ' . $permission .'';

or using double quotes:

$eng['profile_permission'] = "You belong to $group with a permission of $permission";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.