WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : translate.php - Assocciative array example, passing a reference to a function.
Categories : PHP, Arrays, Languages, Variables Click here to Update Your Picture
Ade Morgan
Date : Apr 22nd 2004
Grade : 3 of 5 (graded 3 times)
Viewed : 18450
File : 3844.php
Images : No Images for this code example.
Search : More code by Ade Morgan
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

A round about way to provide multilingual support for your site :) ???



FileName                        ::        translate.php
Author                        ::        Adrian Morgan
Description                ::        Using some assocciative arrays to create a translation
                                        ::        page. Shows how to access array elements using a
                                        ::        posted variable.
                                        ::
DateModified                ::        22/04/2004

FurtherComments        ::        Shows how to pass a reference to a function to affect
                                        ::        global variables. This program could be tackled more
                                        ::        effectively using a database i.e. MySQL


<?php
//-- Create some arrays -- $word[][] for single words -- $phrase[][] for common phrases -- $text[][] for paragraphs or whole items.
//

$word['Help']=array('En'=>'Help', 'Us'=>'Help', 'Es'=>'Ayuda', 'Fr'=>'Aide', 'De'=>'Hilfe', 'Ru'=>'Помощь');
$word['Submit']=array('En'=>'Submit', 'Us'=>'Submit', 'Es'=>'Rendir', 'Fr'=>'Soumettez', 'De'=>'Gehorchen', 'Ru'=>'Подчинитесь');
$phrase['Cat On Mat']=array('En'=>'The cat sat on the colourful mat!',
                           
'Us'=>'The cat sat on the colorful mat!',
                           
'Es'=>'El gato se sentó sobre la estera colorida',
                           
'Fr'=>'Le chat s`est assis sur le tapis coloré',
                           
'De'=>'Die Katze saß auf der bunten Matte',
                           
'Ru'=>'Кот сидел на красочной циновке');
$phrase['Click for help']=array('En'=>'Click<a href="#"> here </a>for '.$word['Help']['En'],
                               
'Us'=>'Click<a href="#"> this </a>to get'.$word['Help']['Us'],
                               
'Es'=>'Chasquido<a href="#"> aquí </a>para'.$word['Help']['Es'],
                               
'Fr'=>'Cliqueter<a href="#"> ici </a>pour'.$word['Help']['Fr'],
                               
'De'=>'Klicken<a href="#"> Sie hier </a>dafür'.$word['Help']['De'],
                               
'Ru'=>'Щелкните<a href="#"> здесь </a>для'.$word['Help']['Ru']);
$text['Disclaimer']=array(    'En'=>'<h1>Disclaimer</h1>This code example will<ol><li>work properly</li>
                                                                                <li>give you a starting point</li>
                                                                                <li>not make your hair grow</li>
                                                                                <li>not pay the mortgage</li></ol>'
,
                   
'Us'=>'<h1>Disclaimer</h1>This code example will<ol><li>execute correctly</li>
                                                                                <li>get you started</li>
                                                                                <li>not stimulate hair growth</li>
                                                                                <li>not keep up your repayments</li></ol>'
,
                   
'Es'=>'<h1>Mentís</h1>Este ejemplo de código va a<ol><li>trabajo correctamente</li>
                                                                                <li>déle un punto de partida</li>
                                                                                <li>no hacen su pelo crecer</li>
                                                                                <li>no pagan la hipoteca</li></ol>'
,
                   
'Fr'=>'<h1>Refus</h1>Cet exemple de code fera<ol><li>Travailler convenablement</li>
                                                                                <li>Vous donner un point de départ</li>
                                                                                <li>Ne pas faire vos cheveux grandissent</li>
                                                                                <li>Ne pas payer l`hypothèque</li></ol>'
,
                   
'De'=>'<h1>Verzichterklärung</h1>Dieses Codebeispiel<ol><li>Arbeit richtig</li>
                                                                                <li>geben Sie Ihnen einen Startpunkt</li>
                                                                                <li>nicht lassen Ihr Haar wachsen</li>
                                                                                <li>nicht bezahlen die Hypothek</li></ol>'
,
                   
'Ru'=>'<h1>Правовая оговорка</h1>Этот кодовый пример будет<ol><li>работа должным образом</li>
                                                                                <li>дайте Вам отправную точку</li>
                                                                                <li>не заставляют ваши волосы расти</li>
                                                                                <li>не платят заклад</li></ol>'
);

$text['Licence']=array(    'En'=>'<h1>Licence</h1>Use this code freely, the translations may be inaccurate, but it makes a useful learning tool!',
                   
'Us'=>'<h1>License</h1>Use this code uninhibited, the translations may not be accurate, but it makes a useful learning tool!',
                   
'Es'=>'<h1>Licencia</h1>¡Use este código libremente, las traducciones pueden ser inexactas, pero hace un instrumento de aprendizaje útil!',
                   
'Fr'=>'<h1>Permis</h1>Utiliser ce code librement, les traductions peuvent être inexactes, mais il fait un outil d`érudition utile!',
                   
'De'=>'<h1>Lizenz</h1>Gebrauchen Sie diesen Code frei, die Übersetzungen können ungenau sein, aber es macht ein nützliches Lernwerkzeug!',
                   
'Ru'=>'<h1>Лицензия</h1>Используйте этот кодекс свободно, переводы могут быть неточны, но это делает полезный инструмент изучения!');

//
//-- End of array definitions
//

//
//-- Create page content -- Write a form to change the language settings
//

//
//-- Check whether this is first visit or whether language has been changed
//

if(isset($language)) // The user has visited & changed the original language.
{
   
$submit = $word['Submit'][$language];
   
write_form($submit); // write_form accepts a reference to $submit.
   
print $phrase['Cat On Mat'][$language]."\n<br /><br />\n";
    print
$text['Disclaimer'][$language];
    print
$text['Licence'][$language]."<br /><br />";
    print
$phrase['Click for help'][$language];
}
else
{
   
$language = "En"; // Set the default language for the first visit to the page.
   
$submit = $word['Submit'][$language];
   
write_form($submit); // write_form accepts a reference to $submit.
   
print $phrase['Cat On Mat'][$language]."\n<br /><br />\n";
    print
$text['Disclaimer'][$language];
    print
$text['Licence'][$language]."<br /><br />";
    print
$phrase['Click for help'][$language];
}

function
write_form(&$sub) // Accept a reference (denoted by [&]) to a var as the argument.
{
    print
"<form method=\"post\">\n";
    print
"<select name=\"language\">\n";
    print
"<option>En</option>\n";
    print
"<option>Us</option>\n";
    print
"<option>Es</option>\n";
    print
"<option>Fr</option>\n";
    print
"<option>De</option>\n";
    print
"<option>Ru</option>\n";
    print
"</select>\n";
    print
"<input type='submit' value=\"$sub\">\n";
    print
"</form>\n";
}
?>



A class to put get and post variables in hidden form elements. Works on scalars, normal arrays, associative arrays.
Categories : Algorithms, Variables, Arrays, PHP, PHP Classes
How to pass an array to a function, or how to define a function wich recieves an array.
Categories : Variables, PHP, Arrays
PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
Categories : PHP, Arrays, Variables
Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
Categories : PHP, Directories, Variables, Arrays
A database abstraction layer for the PHP Oracle 8 module (available from PHP 3.0.5). It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, Oracle, PHP, Arrays, Variables
Simple script to passing persistent and growing array between recalls of one page (manipulate little stack).
Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables
Variable serialization and unserialization. Loading and saving variable structures to and from file.
Categories : Arrays, Filesystem, Variables, Strings, PHP
clearing variables in php3
Categories : Variables, Arrays, PHP
Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI
Categories : Variables, PHP Options and Info, Arrays, URLs, PHP
how to check if a string contains a letter from a different language?
Categories : PHP, Regexps, Languages
Automatic global variable definer
Categories : PHP, Variables, Beginner Guides
PHP Array to Javascript Object
Categories : PHP, Arrays, Java Script
Print out array key => value in colored HTML
Categories : PHP, Arrays, HTML and PHP
This functions makes it easy to use session-variables known from ASP. With one Cookie the array "session" will save and restore from a db-record. In this version MySQL is used but it's should very easy to change
Categories : PHP, Arrays, Cookies, MySQL, Databases
Multilingual php webpage
Categories : PHP, Languages, Cookies