translate.php - Assocciative array example, passing a reference to a function
2006-04-12 01:43
453 查看
<?php /*************************************************************************** /* /* 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 /* /***************************************************************************/ // //-- 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"; } ?>
相关文章推荐
- [C++ Primer] Passing an array to a function by reference/pointers -- sample
- golang passing an array to a function
- [PHP] RSS to Array function
- Passing Array From Javascript To PHP in Joomla!1.5
- Passing PHP array into external Javascript function as array
- Fatal error: Call to a member function fetch_array() on a non-object in E:\wamp\www\shop\index.php
- [php function]arraytoString
- apache,php安装好之后提示Fatal error: Call to undefined function mb_detect_encoding()
- PHP-websocket Call to undefined function socket_create
- PHP解决[function.file-get-contents]: failed to open stream: HTTP request failed!
- (PHP,mysql)Fatal error: Call to undefined function mysql_connect() 解决方案
- undefined reference to `libiconv_open 无法编译PHP
- arrayfunction[LeetCode]Convert Sorted Array to Binary Search Tree
- CentOS 6.5 编译 PHP-7 报错:undefined reference to `libiconv_open 无法编译 PHP libiconv
- CSS五日教程 (reference to http://www.tuqiu.com/study/css/day1_1.php)
- crtbegin_dynamic.o: in function _start:crtbrand.c(.text+0x78): error: undefined reference to 'main
- php ArrayCollection to flex绑定类--flex arrayCollection对应php的数据类型--Zend_Amf与phpamf差别
- PHP-问题处理Fatal error: Uncaught Error: Call to undefined function simplexml_load_file()
- windows下PHP中Fatal error Call to undefined function curl_init()的解决方法
- phpmyadmin error Notice: Array to string conversion in libraries\Error.class.php