我正在寻找一种解码字符串中多个XML标签的"智能方法",我有以下功能:
function b($params) { $xmldata = '' . html_entity_decode($params['data']) . ' '; $lang = ucfirst(strtolower($params['lang'])); if (simplexml_load_string($xmldata) === FALSE) { return $params['data']; } else { $langxmlobj = new SimpleXMLElement($xmldata); if ($langxmlobj -> $lang) { return $langxmlobj -> $lang; } else { return $params['data']; } } }
并尝试
$params['data'] = 'Service DNS DNS Service -DNS Gratuit Free DNS '; $params['lang'] = 'French'; $a = b($params); print_r($a);
但是产出:
Service DNS
我希望它基本上输出每个标签,因此结果应该是:
Service DNS - DNS Gratuit
拉出我的头发.任何快速帮助或指示将不胜感激.
编辑:优化需求.
似乎我不够清楚; 让我举一个例子
如果我有以下字符串作为输入:
TheChat Cat is very happy to stay on stackoverflow because it makes himHeureux Happy to know that it is the bestEndroit Place to find good people with goodRéponses Answers .
因此,如果我使用'French'运行函数,它将返回:
The Chat is very happy to stay on stackoverflow because it makes him Heureux to know that it is the best Endroit to find good people with good Réponses.
用'英语':
The Cat is very happy to stay on stackoverflow because it makes him Happy to know that it is the best Place to find good people with good Answers.
希望现在更清楚了.