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

  • SEARCH
  • Home
  • 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 6340623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:52:16+00:00 2026-05-24T19:52:16+00:00

I have example language file en.php <?php $language = array( language_code => en, language_name

  • 0

I have example language file en.php

<?php

$language = array(
    "language_code" => "en",
    "language_name" => "English",


);

These language files replace replace certain things in template files to support multi-language.

Is there a way to add stuff into the array using PHP?
So I do something in the settings, e.g. add a new language value and the PHP adds this to the file en.php and saves it.

I wonder if this is possible because it can be quite complicated I guess. If it is possible, a slight suggestion to do so would be appreciated. I don’t have much experience editing files in php.

If it would be better, I could change the language format to XML if that makes it easier.

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-05-24T19:52:17+00:00Added an answer on May 24, 2026 at 7:52 pm

    Instead of storing data in php code (or XML), use JSON. Load the data with:

    $json = file_get_contents('en.json');
    if ($json === false) throw new Exception('Cannot read file!');
    $language = json_decode($json, true); // true tells json_decode to export as array ;)
    

    and store it with:

    $json = json_encode($language);
    if (file_put_contents('en.json', $json) === false) {
      throw new Exception('Can not store language');
    }
    

    If you really insist on storing your data as a php program, use the var_export function:

    $phpCode = "<?php\n\n" . '$language = ' . var_export($language, true) . ';';
    if (file_put_contents('en.php', $phpCode) === false) {
        throw new Exception('Can not store language');
    }
    

    There’s no need to use XML, since it would be slower and more complicated than JSON. Also, you should generally not store translations in a (relational) database, since the round trip time and repeated query parsing and evaluation are prone to slow down your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added multi-language using the short article below. When you add for example
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
I have somewhat of a knowledge of the PHP coding language and I would
I used to have one class for one file. For example car.cs has the
I'm writing multilingual website. I have several files on server like: /index.php /files.php /funny.php
If I have example.com/dir and dir is basically a folder in the example.com server,
Anyone have an example snippet showing how to scale a Font using AffineTransform? Thanks.
I have an example in C# code, but it is using streamWriter . It
I have an example of some code that I see often in websites that
I have an example where a protocol would be ideal except for the fact

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.