我是违反任何" PHP的好的做法和QUOT;在下面的PHP阵列与3(人)语言的交易? [英] Am I breaking any "php good practice" in the following php array which deals with 3 (human) languages?

查看:115
本文介绍了我是违反任何" PHP的好的做法和QUOT;在下面的PHP阵列与3(人)语言的交易?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是处理一个多语种网站,我能想到的,现在(不知道)不涉及gettext的,Zend_Translate或者任何PHP插件或框架的最优化的方式。

This is the most optimal way of dealing with a multilingual website I can think of, right now (not sure) which doesn't involve gettext, zend_translate or any php plugin or framework.

我认为它的pretty直截了当:我有3种语言和我写的不同文件中的内容(以阵列的形式),后来,我打电话的内容,以我的指数.PHP 就像你可以在下面的图片AP preciate:

I think its pretty straight forward: I have 3 languages and I write their "content" in different files (in form of arrays), and later, I call that content to my index.php like you can appreciate in the following picture:

我刚开始用PHP,我想知道如果我打破PHP的良好做法,如果code很容易受到XSS攻击,或者如果我写更多code比必要。

I just started with php and I would like to know if I'm breaking php good practices, if the code is vulnerable to XSS attack or if I'm writing more code than necessary.

编辑:我张贴的图片,这样就可以看到文件树(我不是懒惰)

I posted a picture so that you can see the files tree (I'm not being lazy)

EDIT2:我用Vim的主题ir_black和NERDTree

I'm using Vim with the theme ir_black and NERDTree.

推荐答案

看起来没事给我,但我个人preFER创建和使用字典辅助函数:

Looks all right to me, although I personally prefer creating and using a dictionary helper function:

<?php echo dictionary("showcase_li2"); ?>

这将使你以后轻松地切换方法,并让您对您的字典一般更多的控制。另外随着一个数组,你将有范围的问题 - 你将不得不使用将其导入到每一个功能全球$语言; 很烦人

that would enable you to easily switch methods later, and gives you generally more control over your dictionary. Also with an array, you will have the problem of scope - you will have to import it into every function using global $language; very annoying.

您可能也达不到的地步时,你必须插入值到国际化字符串:

You will probably also reach the point when you have to insert values into an internationalized string:

You have %1 votes left in the next %2 hours.
Sie haben %1 stimmen übrig für die nächsten %2 stunden.
Sinulla on %1 ääntä jäljellä seuraavan %2 tunnin ajassa.

这是一个东西辅助函数可以是非常有用的:

that is something a helper function can be very useful for:

<?php echo dictionary("xyz", $value1, $value2 ); ?> 

$值1 $值2 将插入%1 %2 在字典中的字符串。

$value1 and $value2 would be inserted into %1 and %2 in the dictionary string.

这样的辅助函数可以很容易地使用参数数量不受限制 func_get_args()

Such a helper function can easily be built with an unlimited number of parameters using func_get_args().

这篇关于我是违反任何&QUOT; PHP的好的做法和QUOT;在下面的PHP阵列与3(人)语言的交易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆