Greetings,

I have an XML:
<config_root>
<tree_name>
<lang>
<code>he</code>
<name>Hebrew</name>
</lang>
<lang>
<code>en</code>
<name>Enaglish</name>
</lang>
</tree_name>
</config_root>

What functions should I use to add another <lang> node?

thanks

    there is no such function in PHP
    but you can use language modules
    with
    /language/lang.english.php
    /language/lang.hebrew.php
    /language/lang.swedish.php

    This is how we usually do it.
    This way even each user can set his own language preference:
    Now in any page you can use something like this:

    <?php
    // folder 'language' has this contents:
    // /language/lang.english.php
    // /language/lang.hebrew.php
    // /language/lang.swedish.php
    
    // main configuration or each user lang config setting
    // or include "my_settings.php";
    include 'config.php';
    
    // with definition of 
    // $conf_lang = 'hebrew' or 'english' or 'swedish'
    include './language/lang.' . $conf_lang . '.php';
    
    echo $lang[ 'welcome'] . " " . $lang[ 'to_my_website' ] . " " . $username . "!";
    
    ?>

    I did this search with google:

    http://www.google.com/search?num=50&hl=en&q=language+in+php+article+OR+tutorial+lang+english+french+spanish

    🙂 🙂

      Thanks

      Altough I need to work with XML, the language was just an example - you are saying PHP has no intrinsic functions to process/parse XML files?

        There's a couple of ways to do this. I'm not entirely familiar with php's XML functions, but I am fairly familiar with the file functions. Here is an example:

        $filename = "xmlfile.xml";
        $file = file($filename); //place the old contents in an array
        $open = fopen($filename, 'w'); //open the file for writing, clearing it

        //this is the new node of xml
        $newnode = " <lang>\n<code>fr</code>\n<name>French</name>\n</lang>\n";

        //first, write the two head lines of the xml file back to it
        fwrite($open, $file[0]);
        fwrite($open, $file[1]);

        //now write your newest node
        fwrite($open, $newnode);

        //now write the remainder of the old contents to the file
        for ($i = 2; $i <= count($file); $i++) {
        fwrite($open, $file[$i]);
        }
        fclose($open);

        EDIT: Fixed a typo at the end of the $newnode line (was \b, changed to \n)

          Take a look at [man]DOM[/man] it will allow you to add nodes, create your own XML file on the fly etc. It probably will be easier especially with more complicated XML files.

            Write a Reply...