开发者

PHP arrays or MySQL translation? How to?

I would like to create a page that contains just a textarea and placeholder for the output text. The user would enter text into the textarea and while they type (or when the enter button is pressed) the text is translated (or more to the point - swapped out). For example, I might write something like "In my honest opinion", or "to be honest" and that would convert the text to its abbreviated form IMHO and TBH, I thought about doing this with arrays. The text could be searched for the longer strings first, i.e. I thought about have an array of four word phrases, three word phrases, two word ones and a single array of words that can be abbreviated, they could be in "key" => "value" form. Would this开发者_C百科 work, or would mysql work better?


It sounds like you're looking to map full text into abbreviated text. This should work just like actual i18n translation, so any translation implementation would suit.

Even if you don't use Zend Framework, you could look at Zend_Translate adapters to see their supported mapping solutions for a suitable candidate.

Really though, beyond telling you that mapping that key => value is definitely the way to go; how you store the map is entirely up to you.

Updated

$map = array(
    'in my honest opinion' => 'IMHO',
    'to be honest' => 'TBH'
);

// Really simple search/replace
$translated = str_replace(array_keys($map), $map, $string_to_translate);

This shows a really simple search/replace, but the complexity of your replacing will depend on the type of input and the type of replacement you expect

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜